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
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
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
Another simple way different from @mcqueccu the powerhouse from Ghana , but not necessarily superior:
B4X:
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