B4A Library MultiSelectSpinner V1.0.2

MultiSelectSpinner
Author: Manfred Ssykor / DonManfred
Version: 1.02
  • MultiSelectSpinner
    Events:
    • onItemSelected (position As Int, isChecked As Boolean, item As String)
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Items() As String [write only]
      Set the Items for this MultiSelectSpinner
      Example:
      <code>msspinner.Items = Array As String("Apple","Banana","Coconut","Kiwi","Strawberry")</code>
    • Left As Int
    • SelectAllOnFirst As Boolean [write only]
    • SelectedIndicies As List [read only]
      Return a list with all selected indicies
    • SelectedItemsString As String [read only]
      Returns a comma separated String with all selected Items
    • SelectedStrings As List [read only]
      Return a list of selected items as Strings
    • Selection() As String [write only]
      Set the selected items by giving a array of strings
      Example:
      <code>msspinner.Selection = Array As String("Apple","Banana","Strawberry")</code>
    • SelectionByIndicies() As Int [write only]
      Set the slected idicies by giving a array of int
      Example:
      <code>msspinner.SelectionByIndicies = Array As Int(0,1,4)</code>
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int


MultiSelectSpinner001.png
MultiSelectSpinner002.png



This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work) :)


Known problems:
- The Spinner is always in the middle of the screen. I actually dont know how to change this


Example code used to build the two Screenshots
B4X:
    msspinner.Items = Array As String("Apple","Banana","Coconut","Kiwi","Strawberry")
    msspinner.Selection = Array As String("Apple","Banana","Strawberry")
    Dim spitems(100) As String
    For i = 0 To 99
        spitems(i) = "Item "&(i+1)
    Next
    mss2.Items = spitems
 

Attachments

  • msSpinnerEx.zip
    12.2 KB · Views: 799
  • libMultiSelectSpinnerV1.0.0.zip
    6.3 KB · Views: 583
  • libMultiSelectSpinnerV1.0.2.zip
    7.7 KB · Views: 837
Last edited:

johndb

Active Member
Licensed User
Longtime User
An update to this library which would be very useful would be to add an additional check-box above the list. When this check-box is selected, it would select all of the members and when cleared it would clear all of the members.

Thanks,

John
 

DonManfred

Expert
Licensed User
Longtime User
An update to this library which would be very useful would be to add an additional check-box above the list. When this check-box is selected, it would select all of the members and when cleared it would clear all of the members.
Would it be ok to have the option to set SelectAllOnFirst to true and when set to true the first item in the list will act like you wish.
The first item is ignored in the build "complete string"

B4X:
    msspinner.SelectAllOnFirst = True
    msspinner.Items = Array As String("-----","Apple","Banana","Coconut","Kiwi","Strawberry")
    msspinner.Selection = Array As String("Apple","Banana","Strawberry")

MultiSelectSpinner003.png
MultiSelectSpinner004.png
MultiSelectSpinner005.png
 

johndb

Active Member
Licensed User
Longtime User
Would it be ok to have the option to set SelectAllOnFirst to true and when set to true the first item in the list will act like you wish.
The first item is ignored in the build "complete string"

B4X:
    msspinner.SelectAllOnFirst = True
    msspinner.Items = Array As String("-----","Apple","Banana","Coconut","Kiwi","Strawberry")
    msspinner.Selection = Array As String("Apple","Banana","Strawberry")

MultiSelectSpinner003.png
MultiSelectSpinner004.png
MultiSelectSpinner005.png

Yes, Manfred. That would be perfect :)
 

johndb

Active Member
Licensed User
Longtime User
I have started to implement this lib in my app. The following would be useful if not essential:
  • Allow text size to be set in spinner. Designer setting has no effect. Popup text size is ok.
  • Allow text color to be set in spinner. Designer setting as no effect. Popup text color is ok.
  • Provide an event when popup closes. This is required to apply an action when the list is modified.
Thanks for all of your hard work Manfred.

John
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
  • Allow text size to be set in spinner.
It cannot be changed in this library. Internally it is using a Native Alert-Dialogbuilder which has only one Fontsize.
Allow text color to be set in spinner
Same here. The native alertdialog does not expose a Color property

  • Provide an event when popup closes
This should be possible. I´m just trying to implement this
 

DonManfred

Expert
Licensed User
Longtime User
Sadly the event when popup is closed does not work as the library is using a Dialog builder but not using any Buttons to set the positive or negative answers.
This does not work somehow.

But i exposed an ItemClicked event
B4X:
Sub msspinner_onItemSelected(position As Int, isChecked As Boolean, item As String)
    Log("_onItemSelected("&position&","&isChecked&","&item&")")
End Sub
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
_onItemSelected(3,true,Coconut)
_onItemSelected(3,false,Coconut)

Library is updated to V1.0.2 (See Post #1)

Changes:
- Added a boolean flag
B4X:
msspinner.SelectAllOnFirst = True
If this is set to true then the first item will (de-)select all Items. In the build complete-String of all Selected items the first item will not be included in this case.
- Added itemselected event
B4X:
Sub msspinner_onItemSelected(position As Int, isChecked As Boolean, item As String)
    Log("_onItemSelected("&position&","&isChecked&","&item&")")
End Sub
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
_onItemSelected(3,true,Coconut)
_onItemSelected(3,false,Coconut)
 

johndb

Active Member
Licensed User
Longtime User
Sadly the event when popup is closed does not work as the library is using a Dialog builder but not using any Buttons to set the positive or negative answers.
This does not work somehow.

But i exposed an ItemClicked event
B4X:
Sub msspinner_onItemSelected(position As Int, isChecked As Boolean, item As String)
    Log("_onItemSelected("&position&","&isChecked&","&item&")")
End Sub


Library is updated to V1.0.2 (See Post #1)

Changes:
- Added a boolean flag
B4X:
msspinner.SelectAllOnFirst = True
If this is set to true then the first item will (de-)select all Items. In the build complete-String of all Selected items the first item will not be included in this case.
- Added itemselected event
B4X:
Sub msspinner_onItemSelected(position As Int, isChecked As Boolean, item As String)
    Log("_onItemSelected("&position&","&isChecked&","&item&")")
End Sub

There appears to be a problem with the "select all ..." feature. Successive selection of the first item requires multiple "back key" presses in order to exit the selection process.
 

maleche

Active Member
Licensed User
Longtime User
can you set it for single selection? When the user selects another checkbox, any previous checks will become unchecked automatically?
Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
can you set it for single selection? When the user selects another checkbox, any previous checks will become unchecked automatically?
Sounds not logically for me to set single selection to a MultiSelectSpinner.
 

johndb

Active Member
Licensed User
Longtime User
You're right, Speedy, but you might want it allows a single selection on the basis of a given state.
A standard spinner would be used to select a single item. This library is used for multiple selections.

John
 
Top