B4J Question [Solved] Setting Sliders...

BlueVision

Well-Known Member
Licensed User
Longtime User
It may be that I haven't figured it out yet, but all of the B4X sliders I've tested have a common problem:

With most of the sliders I've tested, you can even pass a value that ‘sets’ the slider. You can also query this value afterwards. The problem with this is that the graphical interface never reflects this change. A slider can only be adjusted ‘graphically’ through manual interaction by the user. Or am I completely off base?
Let's be honest. This is completely unsatisfactory. There may be ways to preset a slider to a value and then reflect this change in the view. But this should actually be built into the basic functional principle of a slider when I change the value of a slider (if possible). Just my opinion. If somebody knows the trick, pls. answer to this post.

Cheers from Berlin
 
Solution
The solution:

Add these two subs into your code when using ASRoundSlider + Clock:

B4X:
Public Sub ASRangeRoundSlider1UpdateValue1(newValue As Int)
    ASRangeRoundSlider1.Value1 = newValue
    ASRangeRoundSlider1.Draw
End Sub
Public Sub ASRangeRoundSlider1UpdateValue2(newValue As Int)
    ASRangeRoundSlider1.Value2 = newValue
    ASRangeRoundSlider1.Draw
End Sub

Set the handle (example handle1) with this code to the actual time:
B4X:
    ASRangeRoundSlider1.Value1 = (DateTime.GetHour(DateTime.Now)*60 + DateTime.GetMinute(DateTime.Now)) Mod 720
The mod 720 is needed to display the 24h time correctly on a 12h clock (720 minutes full circle).
If you are using the same line of code in the Value_Changed sub, don't forget to remove...

BlueVision

Well-Known Member
Licensed User
Longtime User
Have you tried calling the .Draw method after setting the values?
Never tried. Probably again one of those things "you have to know". I may be wrong with my opinion. But when setting a value, the view should normally redraw itself to reflect the change as most of the other views do.

Honestly I experimented also with your beautiful AS RoundSlider + Clock and ran into that problem. Set the values and there was no "automatic redraw". It would be exactly the view I need with some modifications in the logical sub for interpreting the value's. There is a small error in interpreting the times in your project. I can show you the problem better in a personal conversation. Maybe it is very fast to fix.
In general I need to set the startvalue (bedtime) depending on actual time of day in my case and to limit the movement of the handles to fixed borders (time).
But setting the value is not enough. Both handles for bedtime and wake point to midnight/noon after setting the value.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In general I need to set the startvalue (bedtime) depending on actual time of day in my case and to limit the movement of the handles to fixed borders (time).
But setting the value is not enough. Both handles for bedtime and wake point to midnight/noon after setting the value.
Can you be more precise on what exactly you want to do.
I have a cross-platform seekbar, not published, which allows to set two limits and updates the graphic when setting the Value property.

1758045286532.png
 
Upvote 0

BlueVision

Well-Known Member
Licensed User
Longtime User
The solution:

Add these two subs into your code when using ASRoundSlider + Clock:

B4X:
Public Sub ASRangeRoundSlider1UpdateValue1(newValue As Int)
    ASRangeRoundSlider1.Value1 = newValue
    ASRangeRoundSlider1.Draw
End Sub
Public Sub ASRangeRoundSlider1UpdateValue2(newValue As Int)
    ASRangeRoundSlider1.Value2 = newValue
    ASRangeRoundSlider1.Draw
End Sub

Set the handle (example handle1) with this code to the actual time:
B4X:
    ASRangeRoundSlider1.Value1 = (DateTime.GetHour(DateTime.Now)*60 + DateTime.GetMinute(DateTime.Now)) Mod 720
The mod 720 is needed to display the 24h time correctly on a 12h clock (720 minutes full circle).
If you are using the same line of code in the Value_Changed sub, don't forget to remove the mod 720, it is needed there.

Thanks to Daestrum and Alexander Stolte for guiding me the right way!
 
Upvote 0
Solution
Top