T Tata Mapassa Active Member Licensed User Longtime User Nov 26, 2023 #1 Good morning, I have a spinner with data from a table like this Cur.GetString("Field1") & ". " & Cur.GetString("Field2") & ", " & Cur.GetString("Field3") & " , " & Cur.GetString("Field4") on a line and I would like the Spinner1_ItemClick action to display only field4. THANKS
Good morning, I have a spinner with data from a table like this Cur.GetString("Field1") & ". " & Cur.GetString("Field2") & ", " & Cur.GetString("Field3") & " , " & Cur.GetString("Field4") on a line and I would like the Spinner1_ItemClick action to display only field4. THANKS
mcqueccu Expert Licensed User Longtime User Nov 26, 2023 #2 Spinner have index starting from zero. So since your Field4 item is the forth item implies its in position 4 -1 of the spinner (3) B4X: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Log(Spinner1.GetItem(3)) 'Hard Coded position 4 or' Log(Spinner1.GetItem(position)) 'Get any selected item' End Sub Upvote 0
Spinner have index starting from zero. So since your Field4 item is the forth item implies its in position 4 -1 of the spinner (3) B4X: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Log(Spinner1.GetItem(3)) 'Hard Coded position 4 or' Log(Spinner1.GetItem(position)) 'Get any selected item' End Sub
mcqueccu Expert Licensed User Longtime User Nov 26, 2023 #3 Based on Further explanation from the French thread https://www.b4x.com/android/forum/threads/spinner-item.157620/post-967445 It means the data is concatenated separated with Comma Sample Data B4X: Dim data As String = "Item 1, Item 2, Item 3, Item 4" 'Assuming this is your concatenated data Spinner1.Add(data) B4X: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Dim dataSplit() As String = Regex.Split(",",Value) 'hard coded position Log(dataSplit(3)) 'or get last itme Log(dataSplit(dataSplit.Length-1)) End Sub Upvote 0
Based on Further explanation from the French thread https://www.b4x.com/android/forum/threads/spinner-item.157620/post-967445 It means the data is concatenated separated with Comma Sample Data B4X: Dim data As String = "Item 1, Item 2, Item 3, Item 4" 'Assuming this is your concatenated data Spinner1.Add(data) B4X: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Dim dataSplit() As String = Regex.Split(",",Value) 'hard coded position Log(dataSplit(3)) 'or get last itme Log(dataSplit(dataSplit.Length-1)) End Sub
M Mahares Expert Licensed User Longtime User Nov 26, 2023 #4 Another simple way different from @mcqueccu the powerhouse from Ghana , but not necessarily superior: Code: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Dim s As String = Value s=s.SubString(s.LastIndexOf(",")+1) Log(s) 'displays the content of field4 End Sub Upvote 0
Another simple way different from @mcqueccu the powerhouse from Ghana , but not necessarily superior: Code: Private Sub Spinner1_ItemClick (Position As Int, Value As Object) Dim s As String = Value s=s.SubString(s.LastIndexOf(",")+1) Log(s) 'displays the content of field4 End Sub
T Tata Mapassa Active Member Licensed User Longtime User Nov 26, 2023 #5 Everyone is welcome, it will help everyone. THANKS Upvote 0