Android Question Change spinner item by index

tonadr

New Member
How can I change a spinner item by item index (not selected item/index)

Code: Copy
MySpinner.Add("a")
MySpinner.Add("b")
MySpinner.Add("Z")
MySpinner.Add("d")
MySpinner.Add("e")

MySpinner.Items(2)="c" '<--
 
If there is a lot of back and forth adding and deleting which will happen then you may use a List/KVS/Map to organize items and small routine to refresh those items in spinner.
 
Upvote 0
How can I change a spinner item by item index (not selected item/index)
If you use B4XComboBox, not the conventional spinner (you need XUI Views Library) checked, you can have the items in a list and do something like this to replace an item with a new one:
Code: Copy
Dim lstItems As List
lstItems.Initialize
    lstItems.AddAll(Array As String("a", "b", "z", "d", "e", "f"))
    lstItems.Set(2, "c")
    B4XComboBox1.cmbBox.Clear
    B4XComboBox1.SetItems(lstItems)    'the new list in the combo will be: a,b,c,d,e,f
Added this 5 minutes later: You can probably use the conventional spinner also:
Code: Copy
sp.Clear
    sp.AddAll(lstItems)
 
Last edited:
Upvote 1
Code: Copy
Spinner1.SelectedIndex = 2

TIP: You should use B4XComboBox from the XUI Views instead Spinner

EDIT: ups, reading Mahare's answer, I've misunderstood your question
 
Last edited:
Upvote 0
Back
Top