Android WheelView Tutorial using Basic4Android
Submitted by donbermoy on Wednesday, January 29, 2014 - 15:00.
Today, I will introduce another tutorial called WheelView. WheelView is a control in android that is used for scrolling, customized items, customized labels, and has event listeners.
On this, you need to create this Sub Globals like this:
This line of code above has the value of the months. We initialized the val variable as the container of the array.
The looping above puts the value of our String Month to our list and will put in the WheelView as we initialized it.
The code above shows the wheelstep that is equal to svstep or 36dip, 1 as first step, the 31 us the last step, True here is for cyclic wheelview (Boolean), and "wv1" as the initialization. Then we put the wheelview to the activity where the code is like this:
The activity adds the view of WheelView for wv1,wv2,wv3 as it concerns with the left size, top size, width, and the height that is being multiplied by 3.
Next, we will initialize the label just like the code below:
After setting to the present date make a sub procedure and named it as show_result. This means that it will read the result of the wheel in wv1, wv2, and wv3. Then the result will be displayed to the label named "result".
Then, code also for showing the result of our WheelView wv1, wv2, and wv3 to display the result in our sub procedure show_result.
Here's the complete code for this tutorial:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09488225971
E-mail:[email protected]
Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky
- Sub Globals
- 'These global variables will be redeclared each time the activity is created.
- 'These variables can only be accessed from this module.
- Dim val(12) As String
- Dim svstep As Int
- Dim wv1,wv2,wv3 As WheelView
- Dim overlay As Panel
- Dim result As Label
- End Sub
Note:
val(12) - our val here is our array variable for creating the months and it has twelve elements. svstep - our variable for initializing a dip wv1,wv2,wv3 - variables used for WheelView overlay - our variable for creating panel result - our variable used for displaying the value of the WheelView Take note: We can use this initialization above without using the designer. Next, we will initialize the value of our wheels. Type the code below:- Sub init_wheels
- Dim lst As List
- lst.Initialize
- val(0) = "Jan"
- val(1) = "Feb"
- val(2) = "Mar"
- val(3) = "Apr"
- val(4) = "May"
- val(5) = "Jun"
- val(6) = "Jul"
- val(7) = "Aug"
- val(8) = "Sep"
- val(9) = "Oct"
- val(10) = "Nov"
- val(11) = "Dec"
- For i = 0 To 11
- lst.Add(val(i))
- Next
- svstep = 36dip
- wv1.Initialize(svstep,1,31,True,"wv1")
- wv2.Initialize1(svstep,lst,True,"wv2") ' using lst as list
- 'wv2.Initialize2(svstep,val,True,"wv2") ' using val as array
- wv3.Initialize(svstep,2000,2030,False,"wv3")
- Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3)
- Activity.AddView(wv2,140dip, 170dip,50dip,svstep*3)
- Activity.AddView(wv3,190dip, 170dip,70dip,svstep*3)
- overlay.Initialize("")
- overlay.SetBackgroundImage(LoadBitmap(File.DirAssets,"cover.png"))
- Activity.AddView(overlay,100dip,170dip,160dip,svstep*3)
- DoEvents
- End Sub
Note:
Dim lst As List - we initialize lst to have our control as List.- val(0) = "Jan"
- val(1) = "Feb"
- val(2) = "Mar"
- val(3) = "Apr"
- val(4) = "May"
- val(5) = "Jun"
- val(6) = "Jul"
- val(7) = "Aug"
- val(8) = "Sep"
- val(9) = "Oct"
- val(10) = "Nov"
- val(11) = "Dec"
- For i = 0 To 11
- lst.Add(val(i))
- Next
- svstep = 36dip
- wv1.Initialize(svstep,1,31,True,"wv1")
- wv2.Initialize1(svstep,lst,True,"wv2") ' using lst as list
- 'wv2.Initialize2(svstep,val,True,"wv2") ' using val as array
- wv3.Initialize(svstep,2000,2030,False,"wv3")
- Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3)
- Activity.AddView(wv2,140dip, 170dip,50dip,svstep*3)
- Activity.AddView(wv3,190dip, 170dip,70dip,svstep*3)
- Sub init_label
- result.Initialize("")
- result.TextSize = 24
- result.Gravity = Gravity.CENTER_HORIZONTAL
- Activity.AddView(result,100dip,100dip,150dip,40dip)
- End Sub
Note:
The code above will display the resulting date which is equal to the present date. Next, we will set the value of wv1 to day, wv2 to month, and wv3 to year. Type this code and named this procedure show_Today:- Sub show_today
- wv1.SetToValue( DateTime.GetDayOfMonth(DateTime.Now))
- wv2.SetToValue( DateTime.GetMonth(DateTime.Now))
- wv3.SetToValue(DateTime.Getyear(DateTime.Now)-2000)
- End Sub
- Sub show_result
- result.Text = wv1.ReadWheel & " " & wv2.ReadWheel & " " & wv3.ReadWheel
- End Sub
- Sub wv1_tick
- show_result
- End Sub
- Sub wv2_tick
- show_result
- End Sub
- Sub wv3_tick
- show_result
- End Sub
- 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.
- Dim val(12) As String
- Dim svstep As Int
- Dim wv1,wv2,wv3 As WheelView
- Dim overlay As Panel
- Dim result As Label
- End Sub
- Sub Activity_Create(FirstTime As Boolean)
- Activity.Title = "WheelView Tutorial - Lyndon Bermoy"
- init_label
- init_wheels
- show_today
- End Sub
- Sub Activity_Resume
- End Sub
- Sub Activity_Pause (UserClosed As Boolean)
- End Sub
- Sub init_label
- result.Initialize("")
- result.TextSize = 24
- result.Gravity = Gravity.CENTER_HORIZONTAL
- Activity.AddView(result,100dip,100dip,150dip,40dip)
- End Sub
- Sub init_wheels
- Dim lst As List
- lst.Initialize
- val(0) = "Jan"
- val(1) = "Feb"
- val(2) = "Mar"
- val(3) = "Apr"
- val(4) = "May"
- val(5) = "Jun"
- val(6) = "Jul"
- val(7) = "Aug"
- val(8) = "Sep"
- val(9) = "Oct"
- val(10) = "Nov"
- val(11) = "Dec"
- For i = 0 To 11
- lst.Add(val(i))
- Next
- svstep = 36dip
- wv1.Initialize(svstep,1,31,True,"wv1")
- wv2.Initialize1(svstep,lst,True,"wv2") ' using lst as list
- 'wv2.Initialize2(svstep,val,True,"wv2") ' using val as array
- wv3.Initialize(svstep,2000,2030,False,"wv3")
- wv1.In
- Activity.AddView(wv1,100dip, 170dip,40dip,svstep*3)
- Activity.AddView(wv2,140dip, 170dip,50dip,svstep*3)
- Activity.AddView(wv3,190dip, 170dip,70dip,svstep*3)
- overlay.Initialize("")
- overlay.SetBackgroundImage(LoadBitmap(File.DirAssets,"cover.png"))
- Activity.AddView(overlay,100dip,170dip,160dip,svstep*3)
- DoEvents
- End Sub
- Sub show_today
- wv1.SetToValue( DateTime.GetDayOfMonth(DateTime.Now))
- wv2.SetToValue( DateTime.GetMonth(DateTime.Now))
- wv3.SetToValue(DateTime.Getyear(DateTime.Now)-2000)
- End Sub
- Sub wv1_tick
- show_result
- End Sub
- Sub wv2_tick
- show_result
- End Sub
- Sub wv3_tick
- show_result
- End Sub
- Sub show_result
- result.Text = wv1.ReadWheel & " " & wv2.ReadWheel & " " & wv3.ReadWheel
- End Sub
Add new comment
- 56 views