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: 717
  • libMultiSelectSpinnerV1.0.0.zip
    6.3 KB · Views: 489
  • libMultiSelectSpinnerV1.0.2.zip
    7.7 KB · Views: 739
Last edited:

ruy

Member
Licensed User
Longtime User
I am adding the multiselectspinner programatically to a customlistview but, when clicked, sends

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

any suggestion
 

Prosg

Active Member
Licensed User
Longtime User
Hello,

I would like to know if your multislectspinner works with map key/value ?

I need somethink like this but with multiselect

spinNiveauDiplomeMap.Initialize
Dim Cursor1 As Cursor
Cursor1 = Main.SQL1.ExecQuery("SELECT id, niveau FROM niveau")
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
spinNiveauDiplome.Add (Cursor1.GetString("niveau"))
spinNiveauDiplomeMap.Put(Cursor1.GetString("niveau"), Cursor1.GetString("id"))
Next
Cursor1.Close


I try this : no success^^ maybe impossible ?

msspinnerMap.Initialize
msspinner.Items = Array As String(msspinnerMap.Put("test1", 1),msspinnerMap.Put("test2",2),msspinnerMap.Put("test3", 3),msspinnerMap.Put("test4", 4))
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
you need to set ITEMS...

try something like

B4X:
    Dim Cursor1 As Cursor
    Cursor1 = Main.SQL1.ExecQuery("SELECT id, niveau FROM niveau")
    Dim sparr(Cursor1.RowCount-1) As String
    For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
        sparr(i) = Cursor1.GetString("niveau")
        'spinNiveauDiplome.Add (Cursor1.GetString("niveau"))
        spinNiveauDiplomeMap.Put(Cursor1.GetString("niveau"), Cursor1.GetString("id"))
    Next
    spinNiveauDiplome.Items = sparr
    Cursor1.Close
 

Prosg

Active Member
Licensed User
Longtime User
ty for your help

They are 6 rows in the datatable

i have a bug : java.lang.ArrayIndexOutOfBoundsException: length=5; index=5

for this line
sparr(i) = Cursor1.GetString("niveau")

i can't explain why
 

LucaMs

Expert
Licensed User
Longtime User
Dim Cursor1 As Cursor
Cursor1 = Main.SQL1.ExecQuery("SELECT id, niveau FROM niveau")
Dim sparr(Cursor1.RowCount-1) As String
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
sparr(i) = Cursor1.GetString(
"niveau")
'spinNiveauDiplome.Add (Cursor1.GetString("niveau"))
spinNiveauDiplomeMap.Put(sparr(i), Cursor1.GetString("id"))
Next
spinNiveauDiplome.Items = sparr
Cursor1.Close

try so
 

Prosg

Active Member
Licensed User
Longtime User
upload_2015-11-7_17-49-6.png
 

Attachments

  • upload_2015-11-7_17-48-56.png
    upload_2015-11-7_17-48-56.png
    37.9 KB · Views: 183

Prosg

Active Member
Licensed User
Longtime User
It's crash the app when i click the spinnermultiselect if i don't use the designer

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim msspinner As MultiSelectSpinner
Dim p As Panel
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("Layout1")
msspinner.Initialize("")
msspinner.AddToParent(Activity, 0,0 ,300dip,100dip)
msspinner.Items = Array As String("Apple","Banana","Coconut","Kiwi","Strawberry")
msspinner.Selection = Array As String("Apple","Banana","Strawberry")

End Sub

The question is : How can i have this multiselectspinner without add it by designer ?
 
Last edited:

imbault

Well-Known Member
Licensed User
Longtime User
Hi @DonManfred ,

Asking the same question, is it possible to have your multiselectspinner without add it by designer?

Thanks
 

imbault

Well-Known Member
Licensed User
Longtime User
It's crash the app when i click the spinnermultiselect if i don't use the designer

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim msspinner As MultiSelectSpinner
Dim p As Panel
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("Layout1")
msspinner.Initialize("")
msspinner.AddToParent(Activity, 0,0 ,300dip,100dip)
msspinner.Items = Array As String("Apple","Banana","Coconut","Kiwi","Strawberry")
msspinner.Selection = Array As String("Apple","Banana","Strawberry")

End Sub

The question is : How can i have this multiselectspinner without add it by designer ?

There is a way to do it, but you did to add a MultiSelectSpinner in the designer :
then in your code, you remove it from Activity then add it somewhere else:


B4X:
    Activity.LoadLayout("Layout1")
    Activity.RemoveViewAt(indexoftheMultSelectSpinner)   
    msspinner.AddToParent(Activity, 0,0 ,300dip,100dip)
 

imbault

Well-Known Member
Licensed User
Longtime User
In the case
.SelectAllOnFirst = True
each time I click the first line, this create an new instance of the view...

Is that a bug Manfred?

Thanks
 

RauchG

Active Member
Licensed User
Longtime User
Hello DonManfred,

if i have a device with an SDK >= 22, includes the multi-spinner when you click on the screen.

In the case of devices SDK < 22 is the only close on the Back-Key.

There is a trick?

Greeting RauchG
 

T201016

Active Member
Licensed User
Longtime User
Hello
I would add my own wish to other people regarding
your interesting solution. Well, with more than a few items to choose from the list
this first element could always be on top. Such a small streamlining case :)

And the question was, did you manage to fix the fault reported by Johna selecting the first item?

greetings
 
Top