Spinner Code Example

pchowning

Member
Licensed User
Longtime User
I have been looking for an example of a spinner function. My application
requires that the spinner support two arguments; i.e. (1) an identity, and
(2) a key that will be returned when the identity is selected. It appears
that little documentation is available on spinners.
 

GMan

Well-Known Member
Licensed User
Longtime User
First you have to fill the Spinner (after dimming and initializing of course):

B4X:
Dim Spinner1 as Spinner
Spinner1.initialize("Spinner1)
Dim Antwort as EditText ' or String - i display datas in a EditText in this case

Spinner1.AddAll (Array As String("Choose...","Item1","Item2","Item3"))

Then you can catch the selction of the spinner like this:
B4X:
If Spinner1.SelectedIndex = "1" Then
Antwort.Text = "1. item"
End If
If Spinner1.SelectedIndex = "2" Then
Antwort.Text = "2. item"
End If

That'S the way i am working with spinners :sign0060:
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Actually, Gman, it is easier if you do this to avoid all the if statements , especially if you have a large spinner, it can be tedious.
B4X:
Sub spinner1_ItemClick (Position As Int, Value As Object)
   Antwort.Text =Value
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
When populating the spinner, you can create a list containing the returned keys. You may then get the desired key by using the position of the spinner.
 
Upvote 0
Top