B4A Library WheelView-Android

The attached project wraps this Github project. You will, other than for the attached B4A library files, need to have a recent version of android-support-v4.jar in you additional library folder. You can download it from HERE. Posting the following:

1. Java Code (you will need to create a folder called libs on the same folder level as the src folder and copy android-support-v4.jar into this folder in order to compile the code.
2. A B4A project demonstrating the WheelView
3. B4A library files (copy them to your additional library folder.

It raises an event in the B4A code when the value of a WheelView changes (see the code). Swipe over them (left to right or vice versa) to change the value of the WheelViews. I have added the views via designer but you can also add them via code. If you add them via code then remember to initialize it for eg as follows:

wva1.Initialize("wva1")

and then have a sub called....
Sub wva1_value_changed

Log(wva1.SelectedPosition)

End sub
....where you can pick up the index of the currently selected item.

1.png


2.png


Sample code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: WheelViewAndroid
    #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 wva1 As WheelViewAndroid
    Private wva2 As WheelViewAndroid
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")
  
    Dim mydata As List
    mydata.Initialize
    Dim interim As String

  
    For i = 0 To 100
        interim = i
        mydata.Add(interim)
    Next
    wva1.Items = mydata
    wva1.AdditionCenterMark = "kg"
    wva1.SelectedIndex = 51
  
    wva1.ArrowColor = Colors.Yellow
    wva1.OtherNumbersColor = Colors.Green
    wva1.OtherTicksColor = Colors.Magenta
  
    wva1.ShowWheel
  

    For i = 0 To 1000
        interim = i
        mydata.Add(interim)
    Next
    wva2.Items = mydata
    wva2.AdditionCenterMark = "mm"
    wva2.SelectedIndex = 501
  
    wva2.ArrowColor = Colors.Green
    wva2.OtherNumbersColor = Colors.Red
    wva2.OtherTicksColor = Colors.Cyan
  
    wva2.ShowWheel
  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub wva1_value_changed
  
    Log("wva1 position selected = " &  wva1.SelectedPosition)
  
End Sub

Sub wva2_value_changed
  
    Log("wva2 position selected = " &  wva2.SelectedPosition)
  
End Sub

The library:

WheelViewAndroid
Author:
Github: kyleduo, Wrapper: Johan Schoeman
Version: 1
  • WheelViewAndroid
    Events:
    • value_changed ( )
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Fling (velocityX As Int, velocityY As Int)
    • 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)
    • ShowWheel
    • smoothSelectIndex (index As Int)
    Properties:
    • AdditionCenterMark As String [write only]
    • ArrowColor As Int [write only]
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Items As List
    • Left As Int
    • OtherNumbersColor As Int [write only]
    • OtherTicksColor As Int [write only]
    • SelectedIndex As Int [write only]
    • SelectedPosition As Int [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int


Enjoy.......;)
 

Attachments

  • b4aWheelViewAndroid.zip
    8 KB · Views: 435
  • TheJavaCode.zip
    8.1 KB · Views: 436
  • WheelViewAndroidLibFiles.zip
    13.3 KB · Views: 435

Johan Schoeman

Expert
Licensed User
Longtime User
An amendment to the B4A code in post #1.

B4X:
    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
 
    Dim mydata As List
    mydata.Initialize
    Dim interim As String

 
    For i = 0 To 100
        interim = i
        mydata.Add(interim)
    Next
    wva1.Items = mydata
    wva1.AdditionCenterMark = "kg"
    wva1.SelectedIndex = 51
 
    wva1.ArrowColor = Colors.Yellow
    wva1.OtherNumbersColor = Colors.Green
    wva1.OtherTicksColor = Colors.Magenta
 
    wva1.ShowWheel
 
    mydata.Clear                    'Add this before the 2nd For i = 0 to.... statement
    For i = 0 To 1000
        interim = i
        mydata.Add(interim)
    Next
    wva2.Items = mydata
    wva2.AdditionCenterMark = "mm"
    wva2.SelectedIndex = 501
 
    wva2.ArrowColor = Colors.Green
    wva2.OtherNumbersColor = Colors.Red
    wva2.OtherTicksColor = Colors.Cyan
 
    wva2.ShowWheel
 
End Sub

Need to clear the list (mydata) before adding new values to it for wva2 else wva2 WheelView will log values in the B4A log that are out by 101

Thanks @Mahares for pointing this out!
 
Last edited:

alienhunter

Active Member
Licensed User
Longtime User
very nice
thank you very much
is there a way to lock the wheel so the user cannot change the values ?
asking because wva1.Enabled=False does not disable it
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
very nice
thank you very much
is there a way to lock the wheel so the user cannot change the values ?
asking because wva1.Enabled=False does not disable it
mmmmm....interesting. Will look into the enabled/disabled issue.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you
Try the attached (new) B4A library files. The enable that you saw was related to the customview and not to the library. Have added some code to the original project so that the wheel can be locked. Use...
B4X:
wva2.WheelLock = False
...to unlock the wheel and use...
B4X:
wva2.WheelLock = True
...to lock the wheel.
 

Attachments

  • WheelViewAndroidNewLibFiles.zip
    13.8 KB · Views: 343

alienhunter

Active Member
Licensed User
Longtime User
Try the attached (new) B4A library files. The enable that you saw was related to the customview and not to the library. Have added some code to the original project so that the wheel can be locked. Use...
B4X:
wva2.WheelLock = False
...to unlock the wheel and use...
B4X:
wva2.WheelLock = True
...to lock the wheel.
thank you again it works
 

alienhunter

Active Member
Licensed User
Longtime User
Hi
i have an array of wheels but when I try to get the sender of it , and it crashes
Any clues ?
Thanks



B4X:
Sub wheel23_value_changed
Dim wheex As WheelViewAndroid
wheex=Sender
Log(wheex.Tag)
End Sub

java.lang.ClassCastException: anywheresoftware.b4a.ShellBA cannot be cast to android.view.View
 

ascot1

Member
Licensed User
Longtime User
hi...johan
great work...
but there's an option for change textsize....thanks in advance
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi...johan
great work...
but there's an option for change textsize....thanks in advance
For a small donation of about EUR 500 000-00 I can probably make it happen. Will look into it over the weekend ;)
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi...johan
great work...
but there's an option for change textsize....thanks in advance
Attached V1.01 of the library files that will allow you to set the text size. Use it as follows:
B4X:
wva1.CenterTextSize = 50
wva1.NormalTextSize = 12

3.png
 

Attachments

  • WheelViewAndroidLibFiles_V1.01.zip
    14 KB · Views: 315
Top