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.
Sample code:
The library:
WheelViewAndroid
Author: Github: kyleduo, Wrapper: Johan Schoeman
Version: 1
Enjoy.......
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.
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 ( )
- ba As BA
- 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)
- 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.......