Sub InitMonths
Months.Initialize
Months.Put("01", "January")
Months.Put("02", "February")
Months.Put("03", "March")
Months.Put("04", "April")
Months.Put("05", "May")
Months.Put("06", "June")
Months.Put("07", "July")
Months.Put("08", "August")
Months.Put("09", "September")
Months.Put("10", "October")
Months.Put("11", "November")
Months.Put("12", "December")
End Sub
I then call this method in my "select" component
B4X:
Sub SetMonths
Clear
Dim Months As Map = SDUIShared.Months
Dim mTot As Int = Months.Size - 1
Dim mCnt As Int = 0
For mCnt = 0 To mTot
Dim mkey As String = Months.GetKeyAt(mCnt)
Dim mval As String = Months.GetValueAt(mCnt)
Log(mkey)
Log(mval)
AddItem(mkey, mval)
Next
End Sub
The end result is incorrect. I was using "for each" clause and decided to check with indexes instead.
It seems normal to me, this is the same behavior as B4J you can't expect the map to be sorted, so you should use B4XOrderedMap but it is not supported by BANano.
B4XOrderedMap from B4XCollections, is a combination of a List with a Map. Avoid calling OrderedMap.Values unless you need to access all values, as it creates and fills a new List each call. The Keys list, on the other hand, is a list maintained by the collection and can be accessed directly...
It seems normal to me, this is the same behavior as B4J you can't expect the map to be sorted, so you should use B4XOrderedMap but it is not supported by BANano.
B4XOrderedMap from B4XCollections, is a combination of a List with a Map. Avoid calling OrderedMap.Values unless you need to access all values, as it creates and fills a new List each call. The Keys list, on the other hand, is a list maintained by the collection and can be accessed directly...
I used the B4xOrderedMap code as is, works perfectly
B4X:
Sub SetMonths
Clear
Dim Months As SDUIMap = SDUIShared.Months
Dim mItems As List = Months.Keys
For Each k As String In mItems
Dim v As String = Months.Get(k)
AddItem(k, v)
Next
End Sub
Had to also add these methods..
B4X:
public Sub GetKeyAt(idx As Int) As Object
Dim s As Int = getSize - 1
If idx >= 0 And idx <= s Then
Dim itemKey As Object = xlist.Get(idx)
Return itemKey
Else
Return Null
End If
End Sub
public Sub GetValueAt(idx As Int) As Object
Dim s As Int = getSize - 1
If idx >= 0 And idx <= s Then
Dim itemKey As Object = xlist.Get(idx)
Dim item As Object = xmap.Get(itemKey)
Return item
Else
Return Null
End If
End Sub