Android Question Wheel View - setToValue and events

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I am using the WheelView library V1.1. It does a nice job, but I have a couple of problems with it.

  1. Wheels aren't changeing when set programatically with whee.SetToValue function.

    I set a wheel programmatically with the following code:

B4X:
Type tblExercise_t( _
exID As Int, _
wgID As Int, _
wgDescription As String, _
weightKg As Double, _                   
repetitions As Int, _
noOfSets As Int, _
comments As String)

Private tblExercise As tblExercise_t

'======================================================================================================
Sub init_wheels(left As Int, right As Int,height As Int,bottom As Int)
    Dim whlList As List
    
    whlList.Initialize
    
  'Get the wheel  lists from the database and use these to initialize the wheels
    whlList = dbRT.getWheelList("tblWeightsList", "weightKG", 0, "Weight ", " kg" )
    whlWeight.Initialize1(height, whlList, True, "whlWeight")
    
    whlList = dbRT.getWheelList("tblWeightsList", "weightKG", 5, "Sets ", "")
    whlNoSets.Initialize1(height,   whlList, True, "whlNoSets") ' using lst as list
    
    whlList = dbRT.getWheelList("tblWeightsList", "weightKG", 0, "Rps ", "" )
    whlReps.Initialize1(height, whlList, True, "whlReps") ' using val as array

    whlNoSets.TextSize     = 13
    whlReps.TextSize     = 13
    whlWeight.TextSize     = 13

    '                           Left                                        Top                                Width            Height
    Activity.AddView(whlReps,  left,                                      100%y - height * 3 - bottom,        (100%x - left - right) / 3, height * 3)
    Activity.AddView(whlNoSets,  whlReps.Width + left,                     100%y - height * 3 - bottom,        (100%x - left - right) / 3, height * 3)
    Activity.AddView(whlWeight,whlReps.Width + whlReps.Width + left,     100%y - height * 3 - bottom,       (100%x - left - right) / 3, height * 3)
    
    overlay.Initialize("")
    overlay.SetBackgroundImage(LoadBitmap(File.DirAssets,"cover.png"))
    Activity.AddView(overlay, left,                                     100%y - height * 3 - bottom,        100%x  - left - right,     height * 3)
    Sleep(0)
End Sub


    Private whlNoSets As WheelView
    Private whlReps As WheelView
    Private whlWeight As WheelView

setWheelsToTarget
....

'======================================================================================================
Sub setWheelsToTarget()
    tblExercise.weightKg = 5

    tblExercise.repetitions = 8

    tblExercise.noOfSets = 3
    whlWeight.SetToValue(tblExercise.weightKg - 1)
    Log("Weight Wheel Index = " & tblExercise.weightKg & "  Weight Wheel Text: " & whlWeight.ReadWheel)

    whlReps.SetToValue(tblExercise.repetitions - 1)
    Log("Reps Wheel Index = " & tblExercise.repetitions & "  Reps Wheel Text: " & whlReps.ReadWheel)

    whlNoSets.SetToValue(tblExercise.noOfSets - 1)
    Log("No of Sets Wheel Index = " & tblExercise.noOfSets & "  No Sets Wheel Text: " & whlNoSets.ReadWheel)

End Sub


'======================================================================================================
public Sub getWheelList(tblName As String, field As String,  Limit As Int, prefix As String, suffix As String) As List
    Dim qryStr As String = "SELECT " & field & " FROM " & tblName  & "  ORDER BY " & field & " ASC"
    Return DBUtils.ExecuteWheel(sqlDB, qryStr, Null, Limit,  prefix, suffix) 
End Sub

If I run the code without breakpoints the wheels are not set. If I run in debug mode and stop on line 58 and step through the wheels move to the correct values. I tried putting sleeps in various places, but this did not provide a fix. I also tried setting the wheel. Delay to 1 ms, but this did not have any effect.

The log output without breakpoints then with breakpoints is shown below:

Log Output No breakpoints then with breakpoints:
No Breakpoints
'--------------------------------------------------------
Weight Wheel Index = 5  Weight Wheel Text: Weight 1 kg
Reps Wheel Index = 8  Reps Wheel Text: Rps 1
No of Sets Wheel Index = 3  No Sets Wheel Text: Sets 1
'--------------------------------------------------------

With Breakpoint - single stepping
'--------------------------------------------------------
Weight Wheel Index = 5  Weight Wheel Text: Weight 5 kg
Reps Wheel Index = 8  Reps Wheel Text: Rps 8
No of Sets Wheel Index = 3  No Sets Wheel Text: Sets 3
'--------------------------------------------------------

I think that the animation should be able to be turned on and off for the SetToValue


2. SetToValue Initiates a wheel tick event.

Setting the wheel value using SetToValue initiates a wheel_tick event as if the user had moved a wheel and it had settled on a value. This is unnecessary behavior, as if the value of a wheel is set programmatically if another variable needs this value then it doesn't need to get it from the wheel this variable can be set programmatically also. I have a feeling that it's this behavior that is causing the problem of the wheels failing to respond to the SetToValue function.

The same problem occurs with other views like tabs. Adding half a dozen tabs programmatically calls the TabStrip1_PageSelected event function each time. This can be useful some of the time, but at other times, it is a pain. Why can't events be disabled/enabled programmatically? Is this possible or does the underlying Java engine prevent this?

An enhancement to the Wheel library would be to make the parameters such as Delay, Color, etc read and write instead of just write only. This read restriction seem to pop up a lot with B4X objects. Is there a reason for this or is it just that the programmer didn't put a get value method in?


Best regards

Rob
 

derez

Expert
Licensed User
Longtime User
... I have a couple of problems with it.
To debug your program will require more than what you supplied, you may try to run one wheel only and see the behavior.
This library is quite old and from its first day the view was very sensitive in operation, required several "doevents" and so on, things that do not comply with today's B4A.
Sorry but I have no intention to jump in again and try to improve it.
I have modified it and created "A new WheelView" https://www.b4x.com/android/forum/threads/91645/#content which is not so sensitive. There are other wheels like clswheel by klaus that you can try.
Sorry again.
 
Upvote 0

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Derez,

Nothing to be sorry about. I understand that their are only so many hours in the day.

Thanks for that info. I will try the new WheelView you recommend. It's a bit hard to keep track of all of the updates and new libraries, because they don't seem to be listed anywhere, they just pop up in posts. But the help I get from the forum usually gets me out of trouble.

I didn't send the whole program because it is fairly large with the wheels only being a small, but important part of it.

Best regards

Rob

PS I tried the new wheel, but I like the swipe feature of the old one, so I would like to have a go at changing the old wheel. Even if I can't get it to work in my app I will learn something and can probably find a work around for my issues.
 
Upvote 0
Top