Android Question Select Default value for WheelView

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am using the following code, and I can't seem to work out how to set the value for the wheel when the app loads.

The wheel has values there, but I want to select 0 Hours, 0 Minutes, 0 Seconds by default but can't seem to work out how.

I have tried doing the following but it didn't work:
B4X:
wv1.SetToValue(0)
wv2.SetToValue(0)
wv3.SetToValue(0)

The full code I ma using is:

B4X:
'Activity module
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)
init_label
init_wheels

End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub init_label
result.Initialize("")
result.TextSize = 10
result.Gravity = Gravity.CENTER_HORIZONTAL
Activity.AddView(result,100dip,100dip,150dip,40dip)
End Sub

Sub init_wheels
Dim list1,list2,list3 As List
If list1.IsInitialized = False Then list1.Initialize
If list2.IsInitialized = False Then list2.Initialize
If list3.IsInitialized = False Then list3.Initialize

For i = 0 To 23
    list1.Add(i & " Hours")
Next

For i = 0 To 59
    list2.Add(i & " Minutes")
    list3.Add(i & " Seconds")
Next


svstep = 56dip '36dip
wv1.Initialize1(svstep,list1,True,"wv1")
wv2.Initialize1(svstep,list2,True,"wv2") ' using lst as list
wv3.Initialize1(svstep,list3,True,"wv3") ' using val as array

wv1.TextSize = 18
wv2.TextSize = 18
wv3.TextSize = 18

Activity.AddView(wv1,0dip, 100%y-svstep*3 - 10dip,100%x / 3,svstep*3)
Activity.AddView(wv2,wv1.Width, 100%y-svstep*3 - 10dip,100%x / 3,svstep*3)
Activity.AddView(wv3,wv1.Width + wv1.Width , 100%y-svstep*3 - 10dip,100%x / 3,svstep*3)
overlay.Initialize("")
overlay.SetBackgroundImage(LoadBitmap(File.DirAssets,"cover.png"))
Activity.AddView(overlay,0dip,100%y-svstep*3 - 10dip,100%x,svstep*3)
DoEvents
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
Dim selectedTime As String
Dim total_time As String
Dim h,s,m As String
 

h = wv1.ReadWheel
m = wv2.ReadWheel
s = wv3.ReadWheel

h = h.Replace (" Hours","")
m = m.Replace (" Minutes","")
s = s.Replace (" Seconds","")

Dim sec As Int
sec=3600*h+60*m+s ' convert time to seconds
total_time = sec

'make number 5 digits long
For i = 1 To 5
    If total_time.Length <= 4 Then
        total_time = "0" & total_time
    End If
Next

result.Text = total_time

End Sub

Anyone know how to select a item from the list such as 0 Hours, 0 Minutes, 0 Seconds ?
(Think it should be the first item from the list)

I have attached a demo project hoping someone can see what I am doing wrong..
 

Attachments

  • DemoProject.zip
    17.8 KB · Views: 207

derez

Expert
Licensed User
Longtime User
Delete and move to activity_resume + change to 1:
B4X:
Sub Activity_Resume
   wv1.SetToValue(1)
   wv2.SetToValue(1)
   wv3.SetToValue(1)
End Sub
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Delete and move to activity_resume + change to 1:
B4X:
Sub Activity_Resume
   wv1.SetToValue(1)
   wv2.SetToValue(1)
   wv3.SetToValue(1)
End Sub
Thank you.. I had tried that but didn't try it in the Activity_Resume sub.
Now that I put it in the Activity_Resume sub it works.

Thanks heaps for your help.
 
Upvote 0
Top