Android Example [B4X] AS Settings - SelectionList Property


With this property, you can offer the user several options and he can then select either one or more.
(57) mage.png

Example
B4X:
    'Second Page
    SettingPage2.Initialize(AS_Settings1,"Page #2")
  
    SettingPage2.AddGroup("MultiOptionExample","Multi Option")
  
    Dim lst_Items As List
    lst_Items.Initialize
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #1",Null,1))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #2",Null,2))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #3",Null,3))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #4",Null,4))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #5",Null,5))
  
    SettingPage2.AddProperty_SelectionList("MultiOptionExample","OptionsExample1",lst_Items,Array(),True,True)
Default Value
The default value is an array, if you dont want a default value, then put an empty array.
B4X:
    Dim lst_Items As List
    lst_Items.Initialize
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #1",Null,1))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #2",Null,2))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #3",Null,3))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #4",Null,4))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Option #5",Null,5))
  
    'Option #1 is default value
    SettingPage2.AddProperty_SelectionList("MultiOptionExample","OptionsExample1",lst_Items,Array(1),True,True)
  
    'Option #1 and Option #5 is default value
    SettingPage2.AddProperty_SelectionList("MultiOptionExample","OptionsExample1",lst_Items,Array(1,5),True,True)
  
    'No default value
    SettingPage2.AddProperty_SelectionList("MultiOptionExample","OptionsExample1",lst_Items,Array(),True,True)
MultiSelect
If true more than one item can selected. If false only one item is selected if you click, it deselect the previous item
2024.02.13_5326.gif
2024.02.13_4815-Trim.gif

CanDeselectAll
If false, then the last item cannot be deselected, it need min one selected

Icons
(58) mage.png

B4X:
    SettingPage2.Initialize(AS_Settings1,"Theme")
  
    SettingPage2.AddGroup("MultiOptionExample","Accent Color")
  
    Dim lst_Items As List
    lst_Items.Initialize
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Green",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_RGB(45, 136, 121)),1))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Blue",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_RGB(73, 98, 164)),2))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Red",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_RGB(221, 95, 96)),3))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Purple",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_RGB(141, 68, 173)),4))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Magenta",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_Magenta),5))
    lst_Items.Add(AS_Settings1.CreateSelectionListItem("Cyan",AS_Settings1.FontToBitmap(Chr(0xF111),False,30,xui.Color_Cyan),6))
  
    SettingPage2.AddProperty_SelectionList("MultiOptionExample","OptionsExample1",lst_Items,Array(1),False,False)
 

Attachments

  • AS Settings SelectionList Example.zip
    179.2 KB · Views: 66
Last edited:

Sergio Haurat

Active Member
Licensed User
Longtime User
Hi @Alexander Stolte, I am trying to implement "SelectionList". I downloaded the example file in #1 and couldn't find a code segment that explains the correct way to do it.

The example code seen above:
- What would be the way to call .ShowPage?
- Is there a way to change the text size of the elements to make them smaller? (I have some records with text that does not look good, so large and with so many characters)

I have managed to run using .ShowPage in .Action, but when selecting an item, it returns the following error.

** Activity (main) Resume **
Error occurred on line: 1604 (AS_SettingsPage)
java.lang.RuntimeException: Object should first be initialized (View).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:335)
at ar.com.sysprofile.psahb.as_settingspage._refreshselectionlistitems(as_settingspage.java:3397)
at ar.com.sysprofile.psahb.as_settingspage._selectionitem_click(as_settingspage.java:3507)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7535)
at android.view.View.performClickInternal(View.java:7512)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29488)
at android.os.Handler.handleCallback(Handler.java:984)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loopOnce(Looper.java:238)
at android.os.Looper.loop(Looper.java:357)
at android.app.ActivityThread.main(ActivityThread.java:8118)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957)

Some code
B4X:
Sub Class_Globals
    Private pnlSettings As AS_Settings
    Private pnlSettingPage As AS_SettingsPage
End Sub
B4X:
        'AS_Settings
        pnlSettings.MainPage.AddGroup("set_basic", mdlFunctions.loc.Localize("def_values"))
        pnlSettings.MainPage.AddDescriptionItem("set_basic", mdlFunctions.loc.Localize("set_fed_club"))
        pnlSettings.MainPage.AddProperty_Action("set_basic", "fed_action", mdlFunctions.loc.Localize("fed"), "", Null, mdlFunctions.loc.Localize("cmb_select"))
        pnlSettings.MainPage.AddGroup("set_advance", mdlFunctions.loc.Localize("set_advance"))
        pnlSettings.MainPage.AddProperty_Boolean("set_advance", "appConnect", mdlFunctions.loc.Localize("set_user_login"), mdlFunctions.loc.Localize("link_app"), Null, False)
        pnlSettingPage.Initialize(pnlSettings, mdlFunctions.loc.Localize("opt_short"))
        pnlSettingPage.AddGroup("selection", mdlFunctions.loc.Localize("fed"))
        Dim lstItems As List
        lstItems.Initialize
        For Each intID As Int In mdlFunctions.map_cmn_lst_federaciones.Keys
            Dim strItem As String = mdlFunctions.map_cmn_lst_federaciones.Get(intID).As (List).Get(0).As (String)
            lstItems.Add(pnlSettings.CreateSelectionListItem(strItem, Null, intID))
        Next
        pnlSettingPage.AddProperty_SelectionList("selection", "federation", lstItems, Array(), False, True)
        pnlSettings.MainPage.Create
        'AS_Settings
B4X:
Private Sub pnlSettings_ActionClicked(Property As AS_Settings_Property)
    Select Case Property.PropertyName
        Case "fed_action"
            pnlSettingPage.ShowPage()
    End Select
End Sub

Graphic example to show you the problem with text size

1709817361665.png
 
Top