Android Code Snippet Multi selection list with B4XPreferencesDialog

If you need lists with more than one choice, one beautiful solution is, to use the B4XPreferencesDialog.
B4X:
Dim mapDaten As Map
    mapDaten.Initialize
    pref.Theme= pref.THEME_LIGHT
    pref.AddSeparator("title")
    pref.AddExplanationItem("", "?", "some explanation")

Dim rs As ResultSet = SQL1.ExecQuery2("SELECT * FROM Items WHERE ..., Array As String(...))
    Do While rs.NextRow
        iID = rs.GetInt("ID")
        sName = rs.GetString("Name")
        'mapDaten.Put(iID, False) 'only needed, if some of the items are allready aktive
        pref.AddBooleanItem(iID, sName)
    Loop
    rs.Close
   
    Wait For (pref.ShowDialog(mapDaten, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        For Each key As String In mapDaten.Keys
            bAktiv = mapDaten.GetDefault(key, False)
            If bAktiv Then
                'handling the choosen items ...
            End If
        Next
    End If
 

Attachments

  • Screenshot_20210809-230611.png
    Screenshot_20210809-230611.png
    137.9 KB · Views: 468
Last edited:
Top