B4A Library Spinner Wheel - Vertical and Horizontal (24 June: new lib files in post #47)

It wraps the Vertical Spinner Wheel part of this Github project. Spin the wheel with a finger - up or down. The spinner is cyclic i.e it acts like a circular buffer.

Posting:
1. B4A project demonstrating the use of the Vertical Spinner Wheel - b4aAndroidSpinnerWheel.zip
2. Zipped files with the required library files (including nineoldandroids) - copy them to your additional library folder. Library files are in AndroidSpinnerWheel.zip

Please note: have added no code in the designer or in the B4A project to position the views - just plonked down and dragged them in the designer. Leaving positioning to those making use of this project.

I will add the Horizontal Spinner Wheel part of the project at some stage...

1.png


Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: AndroidSpinnerWheel
    #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 vsw1, vsw2 As WheelVerticalView
    Dim months() As String
    Dim cities() As String
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")
 
    vsw1.ItemDimmedAlpha = 100
    vsw1.SpinnerTextColor = Colors.Red
    vsw1.SpinnerTextSize = 18
    months = Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    vsw1.SpinnerItems = months
    vsw1.setupSpinnerWheel
 
    vsw2.ItemDimmedAlpha = 150
    vsw2.SpinnerTextColor = Colors.Yellow
    vsw2.SpinnerTextSize = 23 
    cities = Array As String("New York", "Washington", "Chicago", "Atlanta", "Orlando", "Los Angeles", "Houston", "New Orleans") 
    vsw2.SpinnerItems = cities
    vsw2.setupSpinnerWheel
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub vsw1_value_changed(index As Int)
 
    Log("Selected Month = " & months(index))
 
End Sub

Sub vsw2_value_changed(index As Int)
 
    Log("Selected City = " & cities(index))
 
End Sub

The library:

AndroidSpinnerWheel
Author:
Github: Dimitri Fedorov; Wrapped by: Johan Schoeman
Version: 1
WheelVerticalView
Events:

  • value_changed (index as Int )
Fields:
  • ba As BA
Methods:
  • 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)
  • setupSpinnerWheel
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • ItemDimmedAlpha As Int [write only]
  • Left As Int
  • SpinnerItems() As String [write only]
  • SpinnerTextColor As Int [write only]
  • SpinnerTextSize As Int [write only]
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int

 

Attachments

  • AndroidSpinnerWheel.zip
    132.4 KB · Views: 1,229
  • b4aAndroidSpinnerWheel.zip
    11.4 KB · Views: 1,178
Last edited:

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
hi johan,
nice library.
I downloaded library and you project (b4aAndroidSpinnerWheel.zip )
IT WORKS......

Then i copied main.bal into files folder of my project and i create a new module in my project named sosti.
In sosti i copied all instructions of b4aAndroidSpinnerWheel main module and I call sosti from an activity in my project (StartActivity(Sosti))

When I call sosti I have always this error:

** Activity (homepage) Pause, UserClosed = false **
Activity Pause
** Activity (sosti) Create, isFirst = true **
Class not found: androidspinnerwheelwrapper.androidSpinnerWheelWrapper, trying: com.mamavi.holydiet.androidSpinnerWheelWrapper
sosti_activity_create (java line: 362)

the line is:
Activity.LoadLayout("main")

Someone can help me?
Thanks in advance
Marcom
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi johan,
nice library.
I downloaded library and you project (b4aAndroidSpinnerWheel.zip )
IT WORKS......

Then i copied main.bal into files folder of my project and i create a new module in my project named sosti.
In sosti i copied all instructions of b4aAndroidSpinnerWheel main module and I call sosti from an activity in my project (StartActivity(Sosti))

When I call sosti I have always this error:

** Activity (homepage) Pause, UserClosed = false **
Activity Pause
** Activity (sosti) Create, isFirst = true **
Class not found: androidspinnerwheelwrapper.androidSpinnerWheelWrapper, trying: com.mamavi.holydiet.androidSpinnerWheelWrapper
sosti_activity_create (java line: 362)

the line is:
Activity.LoadLayout("main")

Someone can help me?
Thanks in advance
Marcom
Have you copied the /Objects/res folder too? The are xml files in the folders that are required for the B4A project to work. These files must be set to READ ONLY
 

epiCode

Active Member
Licensed User
Hey Johan
Very nice looking spinner !!
I've Two queries?
1. It takes up a lot of space on screen ? can this be zoomed when activated then revert to a minimized icon ? I tried scaling it but it did not work.
2. Would it be possible if there is a timer which does not generate "selected" event in quick succession while user is viewing the options but gets activated once spinning stop or as defined duration after spinning stops to generate final selected value?
 

CaptKronos

Active Member
Licensed User
Longtime User
Just found this great view and have been playing around with the horizontal variant. I have noticed that the spinner's content isn't centred vertically and unfortunately the gravity setting isn't exposed for the horizontal variant, as it is for the vertical. To get around this I used:
B4X:
Sub vertCentreHorizWheel(whv As WheelHorizontalView)
    Dim r As Reflector
    r.Target=whv
    Sleep(0) 'not sure why, but without this sleep the following line results in r being set to null
    r.Target=r.GetField("mItemsLayout")
    r.SetField2("mGravity", Gravity.CENTER_VERTICAL)
    whv.setupSpinnerWheel
End Sub

Also, I found the following two helper functions useful and may address mohsyn's requirement #2:
B4X:
Sub getHorizWheelIndex(whv As WheelHorizontalView) As Int
    Dim r As Reflector
    r.Target=whv
    Return r.GetField("mCurrentItemIdx")
End Sub

Sub getHorizWheelItem(whv As WheelHorizontalView) As String
    Dim r As Reflector
    r.Target=whv
    r.Target=r.GetField("mViewAdapter")
    Dim s() As String=r.GetField("items")
    Return s(getHorizWheelIndex(whv))
End Sub
 

Guenter Becker

Active Member
Licensed User
It wraps the Vertical Spinner Wheel part of this Github project. Spin the wheel with a finger - up or down. The spinner is cyclic i.e it acts like a circular buffer.

Posting:
1. B4A project demonstrating the use of the Vertical Spinner Wheel - b4aAndroidSpinnerWheel.zip
2. Zipped files with the required library files (including nineoldandroids) - copy them to your additional library folder. Library files are in AndroidSpinnerWheel.zip

Please note: have added no code in the designer or in the B4A project to position the views - just plonked down and dragged them in the designer. Leaving positioning to those making use of this project.

I will add the Horizontal Spinner Wheel part of the project at some stage...

View attachment 40875

Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: AndroidSpinnerWheel
    #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 vsw1, vsw2 As WheelVerticalView
    Dim months() As String
    Dim cities() As String
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")
 
    vsw1.ItemDimmedAlpha = 100
    vsw1.SpinnerTextColor = Colors.Red
    vsw1.SpinnerTextSize = 18
    months = Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    vsw1.SpinnerItems = months
    vsw1.setupSpinnerWheel
 
    vsw2.ItemDimmedAlpha = 150
    vsw2.SpinnerTextColor = Colors.Yellow
    vsw2.SpinnerTextSize = 23
    cities = Array As String("New York", "Washington", "Chicago", "Atlanta", "Orlando", "Los Angeles", "Houston", "New Orleans")
    vsw2.SpinnerItems = cities
    vsw2.setupSpinnerWheel
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub vsw1_value_changed(index As Int)
 
    Log("Selected Month = " & months(index))
 
End Sub

Sub vsw2_value_changed(index As Int)
 
    Log("Selected City = " & cities(index))
 
End Sub

The library:

AndroidSpinnerWheel
Author:
Github: Dimitri Fedorov; Wrapped by: Johan Schoeman
Version: 1
WheelVerticalView
Events:

  • value_changed (index as Int )
Fields:
  • ba As BA
Methods:
  • 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)
  • setupSpinnerWheel
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • ItemDimmedAlpha As Int [write only]
  • Left As Int
  • SpinnerItems() As String [write only]
  • SpinnerTextColor As Int [write only]
  • SpinnerTextSize As Int [write only]
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
Hi, well done work!

How is it possible to ad a Click or better long Click event to the view? Code Snipped would be good. Thank you.
 

Liew

Member
Licensed User
Longtime User
It wraps the Vertical Spinner Wheel part of this Github project. Spin the wheel with a finger - up or down. The spinner is cyclic i.e it acts like a circular buffer.

Posting:
1. B4A project demonstrating the use of the Vertical Spinner Wheel - b4aAndroidSpinnerWheel.zip
2. Zipped files with the required library files (including nineoldandroids) - copy them to your additional library folder. Library files are in AndroidSpinnerWheel.zip

Please note: have added no code in the designer or in the B4A project to position the views - just plonked down and dragged them in the designer. Leaving positioning to those making use of this project.

I will add the Horizontal Spinner Wheel part of the project at some stage...

View attachment 40875

Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: AndroidSpinnerWheel
    #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 vsw1, vsw2 As WheelVerticalView
    Dim months() As String
    Dim cities() As String
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")
 
    vsw1.ItemDimmedAlpha = 100
    vsw1.SpinnerTextColor = Colors.Red
    vsw1.SpinnerTextSize = 18
    months = Array As String("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")
    vsw1.SpinnerItems = months
    vsw1.setupSpinnerWheel
 
    vsw2.ItemDimmedAlpha = 150
    vsw2.SpinnerTextColor = Colors.Yellow
    vsw2.SpinnerTextSize = 23
    cities = Array As String("New York", "Washington", "Chicago", "Atlanta", "Orlando", "Los Angeles", "Houston", "New Orleans")
    vsw2.SpinnerItems = cities
    vsw2.setupSpinnerWheel
 
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub vsw1_value_changed(index As Int)
 
    Log("Selected Month = " & months(index))
 
End Sub

Sub vsw2_value_changed(index As Int)
 
    Log("Selected City = " & cities(index))
 
End Sub

The library:

AndroidSpinnerWheel
Author:
Github: Dimitri Fedorov; Wrapped by: Johan Schoeman
Version: 1
WheelVerticalView
Events:

  • value_changed (index as Int )
Fields:
  • ba As BA
Methods:
  • 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)
  • setupSpinnerWheel
Properties:
  • Background As Drawable
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • ItemDimmedAlpha As Int [write only]
  • Left As Int
  • SpinnerItems() As String [write only]
  • SpinnerTextColor As Int [write only]
  • SpinnerTextSize As Int [write only]
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
Hi Johan,
May I know how to put this example to work on b4xpages. I had tried it never works.
Thanks.
Regards,
Liew
 

MarcoRome

Expert
Licensed User
Longtime User
Hi Johan,
May I know how to put this example to work on b4xpages. I had tried it never works.
Thanks.
Regards,
Liew
Can you try:
 
Top