Android Question Spinner item

Tata Mapassa

Member
Licensed User
Longtime User
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

Well-Known Member
Licensed User
Longtime User
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

mcqueccu

Well-Known Member
Licensed User
Longtime User
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

Mahares

Expert
Licensed User
Longtime User
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
 
Upvote 0
Top