Android Question Get selected values from multiple spinners

Sanxion

Active Member
Licensed User
Longtime User
Hi all

I have multiple spinners (8) on a layout and I have specified a single Sub (spnL1A1) in "Event Name" in the designer to handle all their events.

In my Sub spnL1A1, how would I get the value of the selected item and assign it to its local variable - taking in to account there are 8?

For example, in pseudo code it would be:

Sub spnL1A1

'Get the value of the spinner clicked

Select

Case Spinner1
variable1 = spinner1.value

Case Spinner2
variable2 = spinner2.value

End Select

End Sub

etc.

Thanks
 

klaus

Expert
Licensed User
Longtime User
You can use the Sender object and the Spinners Tag property.

Two suggestions:
1. Using something similar to your question.
You must set the Tag property of the Spinners from 1 to x
B4X:
Sub spnL1A1_ItemClick(Position As Int, Value As Object)
    Private spn = Sender As Spinner
    Select spn.Tag
    Case "1"
        variable1 = Value
    Case "2"
        variable2 = Value
    End Select
End Sub

2. Using an array for the values.
You must set the Tag property of the Spinners from 0 to x - 1
B4X:
Sub spnL1A1_ItemClick(Position As Int, Value As Object)
    Private spn = Sender As Spinner
    Private Index = spn.Tag As Int
    variable(Index) = Value
End Sub
 
Upvote 0

Sanxion

Active Member
Licensed User
Longtime User
You can use the Sender object and the Spinners Tag property.

Two suggestions:
1. Using something similar to your question.
You must set the Tag property of the Spinners from 1 to x
B4X:
Sub spnL1A1_ItemClick(Position As Int, Value As Object)
    Private spn = Sender As Spinner
    Select spn.Tag
    Case "1"
        variable1 = Value
    Case "2"
        variable2 = Value
    End Select
End Sub

2. Using an array for the values.
You must set the Tag property of the Spinners from 0 to x - 1
B4X:
Sub spnL1A1_ItemClick(Position As Int, Value As Object)
    Private spn = Sender As Spinner
    Private Index = spn.Tag As Int
    variable(Index) = Value
End Sub

Thank-you Klaus.
 
Upvote 0
Top