iOS Question How to sort Map ?

PumaCyan

Member
Licensed User
Hi all
how to sort a map from an array?

i created a dialog in which it displays the id and name of the month

here is my code to display month list :


B4X:
Sub Daftar_Bulan
    ListDataPanel = xui.CreatePanel("")
    ListDataPanel.SetLayoutAnimated(0, 0, 0, 300dip, 300dip)
    ListDataPanel.LoadLayout("ListTemplate") 'ListTemplate is part of XUI Views library.
    CustomListView1.sv.SetColorAndBorder(xui.Color_Transparent, 0, 0, 0)
    '
    Dim cdBulan As Map = CreateMap(1: "Januari", 2: "Februari", 3: "Maret", 4: "April", _
                                   5: "Mei", 6: "Juni", 7: "Juli", 8: "Agustus", _
                                   9: "September", 10: "Oktober", 11: "November", 12: "Desember")
    '
    For Each bulan As String In cdBulan.Values
        Log(bulan)
    Next
    
    For Each kode As Int In cdBulan.Keys
        Dim bulan As String = cdBulan.Get(kode)
        Log($"Kode : ${kode}, bulan : ${bulan}"$)
        '
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, ListDataPanel.Width ,50dip)
        p.LoadLayout("dialoglsv")
        '
        lblKey.Text = kode
        lblItem.Text = bulan
        CustomListView1.Add(p, Array(kode, bulan))
        '
    Next
End Sub

but the results displayed are not in order on iOS but on Android there is no problem
 

Attachments

  • b4i_err1.png
    b4i_err1.png
    31.8 KB · Views: 56

Sandman

Expert
Licensed User
Longtime User
It's also worth noting that a map isn't guaranteed to keep the order of the items. This is not in the specification, so it's not an error that you get the results that you are getting. If the map contains an array, it will keep the order - also part of the specification.
 
Upvote 0
Top