Spinner View

aymk

Member
Licensed User
Longtime User
Does anyone what does the Position parameter return in the spinner item click event? What is the best way to handle spinner view to show a list of country name and when selected return the short name i.e Display Australia and returns AU, United State returns USA,...

Thanks
 

alfcen

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Globals
   Dim Spinner1 As Spinner
   Dim List1 As List
   Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Label1.Initialize("Label1")
   Spinner1.Initialize("Spinner1")
   Activity.AddView(Spinner1,0,0,100%x,60dip)
   Activity.AddView(Label1,10dip,70dip,100%x,60dip)
   Spinner1.AddAll(Array As String("Australia","Canada","New Zealand","United Kingdom","United States"))
   List1.Initialize
   List1.AddAll(Array As String("AUS","CDN","NZ","UK","USA"))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Spinner1_ItemClick (Position As Int, Value As Object)
   Label1.Text = List1.Get(Position)
End Sub

If the list of countries is longer or complete, then you may wish to load the spinner and List from an external file or database.
 
Upvote 0

aymk

Member
Licensed User
Longtime User
Thanks! I love this forum, very helpful. I hope one day I will be good enough to contribute.
 
Upvote 0

Sortec

Member
Licensed User
Longtime User
The only problem with the above code is a big one, and that problem is that the list needs to also appear when the label is clicked.

Without this, the Spinner doesn't feel correct from a user's perspective.

Is there a way to expand the Spinner menu from the Label's Click event?
 
Upvote 0
Top