The SelectedIndex does not correctly update when removing items via RemoveAtIndex, thus it can end up pointing past the end of the list
In the example below an out of bounds error will occur on the third attempt to remove an item:
In the example below an out of bounds error will occur on the third attempt to remove an item:
B4X:
' Spinner RemoveAt - SelectedIndex not updating
Sub Globals
Dim s As Spinner
Dim b As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
' Spinner
s.Initialize("")
s.Add("Orange")
s.Add("Pear")
s.Add("Banana")
s.Add("Lemon")
s.SelectedIndex=2
' Button
b.Initialize("Button1")
b.Text="Remove item"
Activity.AddView(s,5dip,10dip,200dip,48dip)
Activity.AddView(b,10dip,70dip,150dip,50dip)
End Sub
Sub Button1_Click
If s.Size>0 Then
Log("spinner idx before removing item = " & s.SelectedIndex)
s.RemoveAt(s.SelectedIndex)
Log("spinner idx after removing item = " & s.SelectedIndex)
Log("# items remaining in list: " & s.Size)
Log("==================================")
End If
End Sub
Last edited: