B4A Library Nice Spinner

Johan Schoeman

Expert
Licensed User
Longtime User
Try with the attached library files (V2.01)

B4X:
ns1.SpinnerEnabled = False            'or ns1.SpinnerEnabled = True
 

Attachments

  • NiceSpinner_V2_01.zip
    16.7 KB · Views: 421

jruiz1998

Member
Licensed User
Longtime User
Johan,

I have one more question.
I have several fields to populate and I am using the IME Keyboard.
When I tap the spinner, it displays the menu behind the keyboard and I have to hide the keyboard manually.
Is it possible to hide it automatically when I tap the Label of the ns?. May be something like "ns_item_clicked", but before selecting the item.

Thanks in advance
JRuiz
 

Johan Schoeman

Expert
Licensed User
Longtime User
Try the attached library files (V2.02) and then add this to your B4A code:
B4X:
Sub ns1_spinner_touched
  
    Log("ns1 Spinner Touched")
  
End Sub

See if will help you to sort out the problem. The event will be raised as soon as what you touch the spinner but before the drop-down occurs.
 

Attachments

  • NiceSpinnerLifFiles_V2_02.zip
    16.8 KB · Views: 418
Last edited:

Dave O

Well-Known Member
Licensed User
Longtime User
I'm trying this spinner because it has a public Typeface property, and I want to use it to pick icons using the new Material Icons and FontAwesome fonts.

While the iconified text appears properly in the closed dropdown, the list in the open dropdown does not render (showing just the placeholder symbol).

It seems that the list items are not respecting the Typeface property. Any chance of fixing this?

Thanks!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Dave, I will revisit it sometime during this week - has been more than a year since I have wrapped it.
 

Johan Schoeman

Expert
Licensed User
Longtime User
It seems that the list items are not respecting the Typeface property. Any chance of fixing this?

Thanks!

Dave, try the attached B4A project and new library files (note the invisible label added in the designer):

B4X:
    Dim r1 As List
    r1.Initialize
    r1.AddAll(Array As String("One" & Chr(9) & Chr(9) & Chr(0xF179), "Two"  & Chr(9) & Chr(9) & Chr(0xF17B), "Three" &  Chr(9) & Chr(9) & Chr(0xF17A), "Four" & Chr(9) & Chr(9) & Chr(0xF061), "Five"  & Chr(9) & Chr(9) & Chr(0xF179)))
    Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
    ns1.DividerColor = divcolor
    ns1.DividerHeight = 1
    ns1.DropdownListBackgroundColor = Colors.Green
    ns1.attachDataSource(r1)
   
    'do this after ns1.attachDataSource(r1)
    ns1.DropdownListTypeface = l1.Typeface
    ns1.Typeface = l1.typeface
   
    ns1.DropdownListTextColor = Colors.Magenta
    'the next two lines of code must be before ns1.SelectedIndex is set
    ns1.SelectedTextColor = Colors.Blue
    ns1.SelectedTextBackgroundColor = Colors.White   
    'always set this even if just to 0
    ns1.SelectedIndex = 0
    ns1.SpinnerEnabled = True

 

Attachments

  • NiceSpinnerLibFiles.zip
    17 KB · Views: 390
  • ba4NiceSpinner.zip
    32.2 KB · Views: 407

Dave O

Well-Known Member
Licensed User
Longtime User
Hi Johan, thanks for posting this update so quickly.

I can confirm that when using code to set the properties, the typefaces now work correctly. Thanks.

However, if I add the spinner using the Designer, some of the new properties are not available.

Also (and more importantly), if I set properties like Typeface and Size in the Designer, these are ignored when the app is run. Is that something you can reproduce, or perhaps a problem at my end?

Thanks again!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

How can we clear the items in the dropdown?
Without having to change the library you can perhaps do it with the following code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: NiceSpinner
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False

#End Region

#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 ns1, ns2 As NiceSpinner
    Private b1, b2 As Button
    Dim r1 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")
    ns1.Initialize("ns1")
    ns2.Initialize("ns2")
    b1.Initialize("b1")
    b1.Color = Colors.Blue
    b1.Text = "Clear ns1"
    b1.TextColor = Colors.white
   
    b2.Initialize("b2")
    b2.Color = Colors.Blue
    b2.Text = "Change ns1"
    b2.TextColor = Colors.white
   
    Activity.AddView(ns1, 20%x, 5%y, 20%x, 15%y)
    Activity.AddView(ns2, 60%x, 5%y, 20%x, 15%y)
    Activity.AddView(b1, 5%x, 80%y, 30%x, 20%y)
    Activity.AddView(b2, 40%x, 80%y, 30%x, 20%y)
       

    r1.Initialize
    r1.AddAll(Array As String("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"))
    Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
    ns1.DividerColor = divcolor
    ns1.DividerHeight = 1
    ns1.DropdownListBackgroundColor = Colors.Green
    ns1.attachDataSource(r1)
    ns1.DropdownListTextColor = Colors.DarkGray   
    'the next two lines of code must be before ns1.SelectedIndex is set
    ns1.SelectedTextColor = Colors.Cyan
    ns1.SelectedTextBackgroundColor = Colors.White   
    'always set this even if just to 0
    ns1.SelectedIndex = 0
    ns1.SpinnerEnabled = True
   


    Dim r2 As List
    r2.Initialize         
    r2.AddAll(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))               
    Dim divcolor() As Int = Array As Int(Colors.White, Colors.White, Colors.White)
    ns2.DividerColor = divcolor
    ns2.DividerHeight = 3
    ns2.DropdownListBackgroundColor = Colors.Black
    ns2.attachDataSource(r2)
    ns2.DropdownListTextColor = Colors.White
    'the next two lines of code must be before ns2.SelectedIndex is set   
    ns2.SelectedTextColor = Colors.White
    ns2.SelectedTextBackgroundColor = Colors.DarkGray   
    'always set this even if just to 0
    ns2.SelectedIndex = 2

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ns1_item_clicked
   
    Log("ns1 item " & ns1.SelectedIndex &" selected")
   
End Sub

Sub ns1_spinner_touched
   
    Log("ns1 Spinner Touched")
   
End Sub

Sub ns2_item_clicked
   
    Log("ns2 item " & ns2.SelectedIndex &" selected")
   
End Sub

Sub ns2_spinner_touched
   
    Log("ns2 Spinner Touched")
   
End Sub

Sub b1_click


    ns1.RemoveView
   
    ns1.Initialize("ns1")
    Activity.AddView(ns1, 20%x, 5%y, 20%x, 15%y)

    r1.Initialize
    r1.AddAll(Array As String(""))
    Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
    ns1.DividerColor = divcolor
    ns1.DividerHeight = 1
    ns1.DropdownListBackgroundColor = Colors.Green
    ns1.attachDataSource(r1)
    ns1.DropdownListTextColor = Colors.DarkGray
    'the next two lines of code must be before ns1.SelectedIndex is set
    ns1.SelectedTextColor = Colors.Cyan
    ns1.SelectedTextBackgroundColor = Colors.White
    'always set this even if just to 0
    ns1.SelectedIndex = 0
    ns1.SpinnerEnabled = True
     
   
End Sub


Sub b2_click
   
    ns1.RemoveView
   
    ns1.Initialize("ns1")
    Activity.AddView(ns1, 20%x, 5%y, 20%x, 15%y)

    r1.Initialize
    r1.AddAll(Array As String("A", "1", "B", "2", "C", "3", "D", "4", "E", "5"))
    Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
    ns1.DividerColor = divcolor
    ns1.DividerHeight = 1
    ns1.DropdownListBackgroundColor = Colors.Green
    ns1.attachDataSource(r1)
    ns1.DropdownListTextColor = Colors.DarkGray
    'the next two lines of code must be before ns1.SelectedIndex is set
    ns1.SelectedTextColor = Colors.Cyan
    ns1.SelectedTextBackgroundColor = Colors.White
    'always set this even if just to 0
    ns1.SelectedIndex = 0
    ns1.SpinnerEnabled = True
     
   
End Sub

Try it and see if it works for you

 

ErickAsas

Member
Licensed User
Longtime User
Hi Johan,

Thanks for the reply. I found out that if I manipulate the list attached to the control datasource(attachDataSource) and re-attach it to the control, the list items are changed.

So thanks. No need to remove the view.

Erick
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,
is there a way to change the textsize of the dropdownlist items?
See the attached B4A project and new library files (V2.03)

Use it as follows:
B4X:
ns2.DropdownListTextSize = 10
ns2.SelectedItemTextSize = 15





Sample code:

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

#End Region

#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 ns1, ns2 As NiceSpinner
    Private l1 As Label

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")
'    ns1.Initialize("ns1")
'    ns2.Initialize("ns2")
   
'    Activity.AddView(ns1, 20%x, 5%y, 20%x, 15%y)
'    Activity.AddView(ns2, 60%x, 5%y, 20%x, 15%y)
       
    Dim r1 As List
    r1.Initialize
    r1.AddAll(Array As String("One" & Chr(9) & Chr(9) & Chr(0xF179), "Two"  & Chr(9) & Chr(9) & Chr(0xF17B), "Three" &  Chr(9) & Chr(9) & Chr(0xF17A), "Four" & Chr(9) & Chr(9) & Chr(0xF061), "Five"  & Chr(9) & Chr(9) & Chr(0xF179)))
    Dim divcolor() As Int = Array As Int(Colors.Blue, Colors.Green, Colors.Red)
    ns1.DividerColor = divcolor
    ns1.DividerHeight = 1
    ns1.DropdownListBackgroundColor = Colors.Green
    ns1.attachDataSource(r1)
   
    'do this after ns1.attachDataSource(r1)
    ns1.DropdownListTypeface = l1.Typeface
    ns1.Typeface = l1.typeface
   
    ns1.DropdownListTextColor = Colors.Magenta
    'the next two lines of code must be before ns1.SelectedIndex is set
    ns1.SelectedTextColor = Colors.Blue
    ns1.SelectedTextBackgroundColor = Colors.White   
    'always set this even if just to 0
    ns1.SelectedIndex = 0
    ns1.SpinnerEnabled = True



    Dim r2 As List
    r2.Initialize         
    r2.AddAll(Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"))               
    Dim divcolor() As Int = Array As Int(Colors.White, Colors.White, Colors.White)
    ns2.DividerColor = divcolor
    ns2.DividerHeight = 3
    ns2.DropdownListBackgroundColor = Colors.Black
    ns2.attachDataSource(r2)
    ns2.DropdownListTextColor = Colors.White
    ns2.DropdownListTextSize = 10
    ns2.SelectedItemTextSize = 15
    'the next two lines of code must be before ns2.SelectedIndex is set   
    ns2.SelectedTextColor = Colors.White
    ns2.SelectedTextBackgroundColor = Colors.DarkGray   
    'always set this even if just to 0
    ns2.SelectedIndex = 2

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub ns1_item_clicked
   
    Log("ns1 item " & ns1.SelectedIndex &" selected")
   
End Sub

Sub ns1_spinner_touched
   
    Log("ns1 Spinner Touched")
   
End Sub

Sub ns2_item_clicked
   
    Log("ns2 item " & ns2.SelectedIndex &" selected")
   
End Sub

Sub ns2_spinner_touched
   
    Log("ns2 Spinner Touched")
   
End Sub
 

Attachments

  • NiceSpinnerLibFilesV2.03.zip
    17.2 KB · Views: 496
  • b4aNiceSpinner25022017.zip
    32.3 KB · Views: 468

bigbadfred

Member
Licensed User
Longtime User
Wow!
Thanks a lot, Johan, for your thorough reply.
I will try this out tonight and will let you know how it went.
Thanks again, I can make good use of this.
 

Lakhtin_V

Active Member
Licensed User
Longtime User
Hi! not working with Lib Ver1 and Lib Ver2

when I use it I get bellow exception:
android.content.res.Resources$NotFoundException: Resource ID #0x0

Xiome Note 3 Pro , Android 6.0.1
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi! not working with Lib Ver1 and Lib Ver2

when I use it I get bellow exception:
android.content.res.Resources$NotFoundException: Resource ID #0x0

Xiome Note 3 Pro , Android 6.0.1
See post #18
 

taylorw

Active Member
Licensed User
Hi all, i have follow the step to downloaad "android-support-v4.jar" and paste in B4A library folder.
Below is my error.

B4X:
Error occurred on line: 42 (frmItem_Maintenance)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at b4a.example.frmitem_maintenance.afterFirstLayout(frmitem_maintenance.java:102)
    at b4a.example.frmitem_maintenance.access$000(frmitem_maintenance.java:17)
    at b4a.example.frmitem_maintenance$WaitForLayout.run(frmitem_maintenance.java:80)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:5621)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:158)
    ... 17 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
    at android.content.res.Resources.getValue(Resources.java:1384)
    at android.content.res.Resources.getDimensionPixelSize(Resources.java:725)
    at main.java.org.angmarch.views.NiceSpinner.init(NiceSpinner.java:127)
    at main.java.org.angmarch.views.NiceSpinner.<init>(NiceSpinner.java:72)
    at nicespinnerwrapper.niceSpinnerWrapper._initialize(niceSpinnerWrapper.java:105)
    ... 20 more
** Activity (frmitem_maintenance) Resume **
 

Johan Schoeman

Expert
Licensed User
Longtime User
See post #18. You are missing the files in the B4A project's /Objects/res/bla bla folders. These files need to set to READ ONLY else they will be deleted the first time that you compile the B4A app.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…