Android Question Spinner options

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Is it possible to use a spinner with two values? The visible value and a selected value?

As far as I could see there is only the possibility to get the selected index.

Best regards,
André Hilberink
 

barx

Well-Known Member
Licensed User
Longtime User
No you would have to keep a map for the key/value pairs and reference that.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
I stand corrected, my bad.

Disclaimer in signature...... :confused::oops:;)
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
no no no no
that first line of my sig states

Don't take my answers as gospel, I'm usually wrong...
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Thanks everyone for your answers.

As it seems to have the need of two objects for every spinner, I just choose to define a List for every Spinner and load these synchrome.
Now I can call the value by the Get function of the List object.

I hoped there was an easy way :-(

Best regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim Spinner1 As Spinner
Dim SpinList1 As List

Dim SelectedID As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

Activity.LoadLayout("Main")

SpinList1.Initialize
Spinner1.AddAll(Array As String("Text1","Text2","Text3","Text4"))
SpinList1.AddAll(Array As String("ID1","ID2","ID3","ID4"))
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Spinner1_ItemClick (Position As Int, Value As Object)
SelectedID = SpinList1.Get(Spinner1.SelectedIndex)

Log(SelectedID)
End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Is this what you have in mind:

B4X:
Sub Globals
    Dim Spinner1 As Spinner
    Dim SpinList1 As List
    Dim SpinMap As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("Main")  'Contains  spinner1

    SpinList1.Initialize
    SpinMap.Initialize
    Spinner1.AddAll(Array As String("Text1","Text2","Text3","Text4"))
    SpinList1.AddAll(Array As String("ID1","ID2","ID3","ID4"))
    For i=0 To Spinner1.Size-1  
       SpinMap.Put(Spinner1.GetItem(i), SpinList1.Get(i))
    Next
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Spinner1_ItemClick (Position As Int, Value As Object)
    Dim Myid As String
    Myid = SpinMap.Get(Value)
    Log(Myid)
End Sub
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Thanks for all the replies.

I wonder if someone can tell me why to use a Map, instead of a List?

I do get my value using:
B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
SelectedID = SpinList1.Get(Spinner1.SelectedIndex)

Log(SelectedID)
End Sub

Best regards,
André
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Hi,

Thanks for all the replies.

I wonder if someone can tell me why to use a Map, instead of a List?

I do get my value using:
B4X:
Sub Spinner1_ItemClick (Position As Int, Value As Object)
SelectedID = SpinList1.Get(Spinner1.SelectedIndex)

Log(SelectedID)
End Sub

Best regards,
André


In this case, use a List or a Map makes no difference.
But the Maps can contain objects, not just text, and in other cases they are more useful.

My suggestion is to put the List or Map in the Tag Spinner, instead of declaring it as a global variable
 
Upvote 0
Top