B4J Library [ABMaterial]: MultiPicker

Discussion in 'B4J Libraries & Classes' started by Mashiane, Aug 5, 2018.

  1. Mashiane

    Mashiane Expert Licensed User

    Ola

    This is some nice multipicker i found, it could be useful one day.

    MashMultiPicker.gif

    Code:
    mmp.Initialize(page,"days",True)
        mmp.AddListItem(
    "sun","Su")
        mmp.AddListItem(
    "mon","Mo")
        mmp.AddListItem(
    "tue","Tu")
        mmp.AddListItem(
    "wed","We")
        mmp.AddListItem(
    "thu","Th")
        mmp.AddListItem(
    "fri","Fr")
        mmp.AddListItem(
    "sat","Sa")
        
    page.Cell(2,1).AddComponent(mmp.ABMComp)
        
        
    Dim chkb As MashMultiPicker
        chkb.Initialize(
    page,"proglang",False)
        chkb.AddCheckBoxItem(
    "c","JAN",True)
        chkb.AddCheckBoxItem(
    "js","FEB",False)
        chkb.AddCheckBoxItem(
    "swift","MAR",True)
        chkb.AddCheckBoxItem(
    "java","APR",False)
        chkb.AddCheckBoxItem(
    "csharp","MAY",False)
        chkb.AddCheckBoxItem(
    "cpp","JUN",True)
        chkb.AddCheckBoxItem(
    "php","JUL",False)
        chkb.AddCheckBoxItem(
    "aug","AUG",False)
        chkb.AddCheckBoxItem(
    "sep","SEP",False)
        chkb.AddCheckBoxItem(
    "oct","OCT",False)
        chkb.AddCheckBoxItem(
    "nov","NOV",False)
        chkb.AddCheckBoxItem(
    "dev","DEC",False)
        chkb.AddSelection(
    "cpp")
        chkb.AddSelection(
    "sep")
        
    page.Cell(3,1).AddComponent(chkb.ABMComp)
    Will add the events later on..
     

    Attached Files:

    jmon, amaxco, inakigarm and 2 others like this.
  2. Mashiane

    Mashiane Expert Licensed User

    Did some house cleaning..

    MashMultiPicker.gif


    1. Only 1 method i.e. AddItem is used to add items
    2. Added onSelect event
    3. Added onUnselect event
    4. Added functionality to return selected items

    Define control in ClassGlobals

    Code:
    Dim mmp As MashMultiPicker
    On ConnectPage add control

    Code:
    mmp.Initialize(page,"days")
        mmp.AddItem(
    "sun","Su",True)
        mmp.AddItem(
    "mon","Mo",False)
        mmp.AddItem(
    "tue","Tu",True)
        mmp.AddItem(
    "wed","We",False)
        mmp.AddItem(
    "thu","Th",False)
        mmp.AddItem(
    "fri","Fr",False)
        mmp.AddItem(
    "sat","Sa",True)
        
    page.Cell(2,1).AddComponent(mmp.ABMComp)
    Trap Events

    Code:
    Sub days_select(value As Map)
        
    'return selected items on select
        Dim opt As String = value.Get("value")
        
    page.Msgbox("",opt,"Select","OK",False,"","")
        
      
        
    End Sub

    Sub days_unselect(value As Map)
        
    'Dim opt As String = value.Get("value")
        'page.Msgbox("",opt,"Unselect","OK",False,"","")
        Dim sel As String = mmp.GetSelection
        
    page.Msgbox("",sel,"Unselect","OK",False,"","")
        
    End Sub
    Another way to get selected items from another sub

    Code:
    Dim sel As String = mmp.GetSelection
        
    page.Msgbox("",sel,"Unselect","OK",False,"","")
     

    Attached Files:

  3. Mashiane

    Mashiane Expert Licensed User

    This should be the final version. What's new? Removed the array that was being pushed at each element select/unselect and used a built in method to get selected items, this has ensured that this can be used to select one item at a time too.

    MultiPicker.png

    The true in initialize is telling the component that it should be single select i.e. multiple selections off.

    Example:

    Code:
    wdays.Initialize(page,"wdays",True)
        
    Dim wdays1 As Map = CreateMap("1":"Sun", _
        
    "2":"Mon", _
        
    "3":"Tue", _
        
    "4":"Wed", _
        
    "5":"Thu", _
        
    "6":"Fri", _
        
    "7":"Sat")
        
    For ddc = 0 To 6
            
    Dim wdn As String = wdays1.GetKeyAt(ddc)
            
    Dim wdm As String = wdays1.GetValueAt(ddc)
            wdays.AddItem(wdn,wdm,
    False)
        
    Next
        
    page.Cell(1,1).AddComponent(wdays.ABMComp)
        
        days.Initialize(
    page,"weekday",True)
        
    For ddc = 1 To 31
            days.AddItem(ddc,ddc,
    False)
        
    Next
        
    page.Cell(2,1).AddComponent(days.ABMComp)
        
        
    Dim months As Map = CreateMap("1":"Jan", _
        
    "2":"Feb", _
        
    "3":"Mar", _
        
    "4":"Apr", _
        
    "5":"May", _
        
    "6":"Jun", _
        
    "7":"Jul", _
        
    "8":"Aug", _
        
    "9":"Sep", _
        
    "10":"Oct", _
        
    "11":"Nov", _
        
    "12":"Dec")
        
        mmp.Initialize(
    page,"days",False)
        
    Dim mTot As Int = months.Size - 1
        
    Dim mCnt As Int
        
    For mCnt = 0 To mTot
            
    Dim mnum As String = months.GetKeyAt(mCnt)
            
    Dim mnam As String = months.GetValueAt(mCnt)
            mmp.AddItem(mnum,mnam,
    False)
        
    Next
        
    page.Cell(2,1).AddComponent(mmp.ABMComp)
    In the instances above, the numeric ids will be what will be returned. I like that this is responsive too.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice