B4A Library PickerView

A (shortcut) wrap for this Github project. Download and extract PickerLibRes.zip and resource.zip and then copy these two folders to be on the same folder level as the /Files and /Objects folders of the B4A project.

The demo project includes a single, double, and triple picker.
Take note of the B4A manifest file
Make sure you enable AppCompat V3.20
See the B4A log for the values that are returned (via events) by each of the pickers


1.gif



Library:
PickerViewMulti
Author:
Github: Ramesh Bhupathi, Wrapped by: Johan Schoeman
Version: 1
  • DoublePickerView
    Events:
    • double_picker_values_selected (index1 As Int, index2 As Int)
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartDoublePicker
    • setCyclical (cyclical_1 As Boolean, cyclical_2 As Boolean)
    • setSelectedIndex (selectedindex1 As Int, selectedindex2 As Int)
    Properties:
    • BtnCancelText As String [write only]
    • BtnCancelTextColor As Int [write only]
    • BtnSubmitText As String [write only]
    • BtnSubmitTextColor As Int [write only]
    • Option1DividerColor As Int [write only]
    • Option1TextColorCenter As Int [write only]
    • Option1TextColorOut As Int [write only]
    • Option2DividerColor As Int [write only]
    • Option2TextColorCenter As Int [write only]
    • Option2TextColorOut As Int [write only]
    • PickerTitle As String [write only]
    • WheelItems1 As ArrayList [write only]
    • WheelItems2 As ArrayList [write only]
  • SinglePickerView
    Events:
    • single_picker_value_selected (index As Int)
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartSinglePicker
    Properties:
    • BtnCancelText As String [write only]
    • BtnCancelTextColor As Int [write only]
    • BtnSubmitText As String [write only]
    • BtnSubmitTextColor As Int [write only]
    • Cyclical As Boolean [write only]
    • PickerTitle As String [write only]
    • SelectedIndex As Int [write only]
    • SingleDividerColor As Int [write only]
    • SingleTextColorCenter As Int [write only]
    • SingleTextColorOut As Int [write only]
    • WheelItems As ArrayList [write only]
  • TriplePickerView
    Events:
    • triple_picker_values_selected (index1 As Int, index2 As Int, index3 As Int)
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartTriplePicker
    • setCyclical (cyclical_1 As Boolean, cyclical_2 As Boolean, cyclical_3 As Boolean)
    • setSelectedIndex (selectedindex1 As Int, selectedindex2 As Int, selectedindex3 As Int)
    Properties:
    • BtnCancelText As String [write only]
    • BtnCancelTextColor As Int [write only]
    • BtnSubmitText As String [write only]
    • BtnSubmitTextColor As Int [write only]
    • Option1DividerColor As Int [write only]
    • Option1TextColorCenter As Int [write only]
    • Option1TextColorOut As Int [write only]
    • Option2DividerColor As Int [write only]
    • Option2TextColorCenter As Int [write only]
    • Option2TextColorOut As Int [write only]
    • Option3DividerColor As Int [write only]
    • Option3TextColorCenter As Int [write only]
    • Option3TextColorOut As Int [write only]
    • PickerTitle As String [write only]
    • WheelItems1 As ArrayList [write only]
    • WheelItems2 As ArrayList [write only]
    • WheelItems3 As ArrayList [write only]

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aPickerViewMulti
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\PickerLibRes


'#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google-play-services\libproject\google-play-services_lib\res, com.google.android.gms
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
       
    Dim spv As SinglePickerView
    Dim dpv As DoublePickerView
    Dim tpv As TriplePickerView
   
    Dim singlelist As List
   
    Dim doublelist1 As List
    Dim doublelist2 As List
   
    Dim triplelist1 As List
    Dim triplelist2 As List   
    Dim triplelist3 As List       
   
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
   
    Activity.LoadLayout("main")
   
    spv.Initialize("spv")
    dpv.Initialize("dpv")
    tpv.Initialize("tpv")
   
   
    singlelist.Initialize
    singlelist.AddAll(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))
    spv.WheelItems = singlelist
    spv.Cyclical = True
    spv.PickerTitle = "Months"
    spv.SelectedIndex = 1
   
    spv.SingleTextColorOut = Colors.LightGray
    spv.SingleTextColorCenter = Colors.Black
    spv.SingleDividerColor = Colors.Blue
   
    spv.BtnCancelText = "CANS"
    spv.BtnSubmitText = "SUBS"
   
    spv.BtnCancelTextColor = Colors.Red
    spv.BtnSubmitTextColor = Colors.Green
   
'*************************************************************************************************************************************
   
    doublelist1.Initialize
    doublelist1.AddAll(Array As String("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"))
    dpv.WheelItems1 = doublelist1
   
   
    doublelist2.Initialize
    doublelist2.AddAll(Array As String("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
    dpv.WheelItems2 = doublelist2   
   
    dpv.setCyclical(True, True)
    dpv.setSelectedIndex(2, 3)
    dpv.PickerTitle = "Double Data"
   
    dpv.Option1TextColorOut = Colors.Green
    dpv.Option1TextColorCenter = Colors.Red
   
    dpv.Option2TextColorOut = Colors.Red
    dpv.Option2TextColorCenter = Colors.Green
   
    dpv.Option1DividerColor = Colors.Magenta
    dpv.Option2DividerColor = Colors.Cyan
   
    dpv.BtnCancelText = "QUIT"
    dpv.BtnSubmitText = "GO"
   
    dpv.BtnCancelTextColor = Colors.Black
    dpv.BtnSubmitTextColor = Colors.Cyan
   
    '************************************************************************************************************************************
   
    triplelist1.Initialize
    triplelist1.AddAll(Array As String("2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020"))
    triplelist2.Initialize
    triplelist2.AddAll(Array As String("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"))
    triplelist3.Initialize
    triplelist3.AddAll(Array As String("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"))
   
    tpv.WheelItems1 = triplelist1
    tpv.WheelItems2 = triplelist2
    tpv.WheelItems3 = triplelist3
   
    tpv.setCyclical(True, True, True)
    tpv.setSelectedIndex(6, 9, 0)
    tpv.PickerTitle = "Triple Data"   
   
    tpv.Option1TextColorOut = Colors.Green
    tpv.Option1TextColorCenter = Colors.Red
   
    tpv.Option2TextColorOut = Colors.Red
    tpv.Option2TextColorCenter = Colors.Green
   
    tpv.Option3TextColorOut = Colors.Blue
    tpv.Option3TextColorCenter = Colors.Cyan
   
    tpv.Option1DividerColor = Colors.Red
    tpv.Option2DividerColor = Colors.Green
    tpv.Option3DividerColor = Colors.Black   
   
    tpv.BtnCancelText = "NO"
    tpv.BtnSubmitText = "YES"
   
    tpv.BtnCancelTextColor = Colors.Magenta
    tpv.BtnSubmitTextColor = Colors.Black

   
End Sub

Sub Activity_Resume
   

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click

    spv.StartSinglePicker

End Sub

Sub Button2_Click
   
    dpv.StartDoublePicker   
   
End Sub

Sub Button3_Click
   
    tpv.StartTriplePicker
   
End Sub


Sub spv_single_picker_value_selected(index As Int)
   
    'if index = -1 then the user as clicked on CANCEL
    Log("selected index = " & index)
    If index <> -1 Then
      Log("Selected Value = " & singlelist.Get(index))
    Else
      Log("User clicked on CANCEL") 
    End If
   
End Sub

Sub dpv_double_picker_values_selected(index1 As Int, index2 As Int)
   
    'if index1 = -1 then the user as clicked on CANCEL
    Log("Selected index1 = " & index1 & "  Selected index2 = " & index2)
    If index1 <> -1 Then
      Log("Selected Value1 = " & doublelist1.Get(index1))
      Log("Selected Value2 = " & doublelist2.Get(index2))     
    Else
      Log("User clicked on CANCEL") 
    End If
   
End Sub

Sub tpv_triple_picker_values_selected(index1 As Int, index2 As Int, index3 As Int)
   
    'if index1 = -1 then the user as clicked on CANCEL
    Log("selected index1 = " & index1 & "  Selected index2 = " & index2 & "  Selected index3 = " & index3)
    If index1 <> -1 Then
      Log("Selected Value1 = " & triplelist1.Get(index1))
      Log("Selected Value2 = " & triplelist2.Get(index2))   
      Log("Selected Value3 = " & triplelist3.Get(index3))         
       
    Else
      Log("User clicked on CANCEL") 
    End If
   
End Sub
 

Attachments

  • b4aPickerViewMulti.zip
    9.5 KB · Views: 334
  • PickerViewMultiLibFiles.zip
    72.7 KB · Views: 325
  • TheJavaCode.zip
    34.6 KB · Views: 326
  • PickerLibRes.zip
    5.2 KB · Views: 331
  • resource.zip
    423 bytes · Views: 332
Top