B4J Question Slider step

red30

Well-Known Member
Licensed User
Longtime User
I use the slider (1..10) with the settings:
B4X:
    joSlider.RunMethod("setBlockIncrement", Array(0.3))
    joSlider.RunMethod("setMajorTickUnit", Array(1.0))
    joSlider.RunMethod("setMinorTickCount", Array(2))
    joSlider.RunMethod("setShowTickLabels", Array(True))
    joSlider.RunMethod("setShowTickMarks", Array(True))
    joSlider.RunMethod("setValueChanging", Array(True))
    joSlider.RunMethod("setSnapToTicks", Array(True))
I turn to Private Sub Slider1_ValueChange (Value As Double)for any slider shift. Can I do something to make the slider move only in steps?
1,1.33,1,66.1.99,2.33 and so on...
I do not want to go to Slider1_ValueChange at intermediate values
 

stevel05

Expert
Licensed User
Longtime User
This will do what you want
B4X:
JoSlider.RunMethod("setSnapToTicks", Array(True))
    JoSlider.RunMethod("setBlockIncrement", Array(0.3))
    JoSlider.RunMethod("setMajorTickUnit", Array(1.0))
    JoSlider.RunMethod("setMinorTickCount", Array(2))
    JoSlider.RunMethod("setShowTickLabels", Array(True))
    JoSlider.RunMethod("setShowTickMarks", Array(True))

B4X:
Sub Slider1_ValueChange (Value As Double)
    Dim JO As JavaObject = Sender
    If JO.RunMethod("isValueChanging",Null) Then Return
    Log("New value: " & Value)
End Sub

setValueChanging is not required and is set by the system when needed.
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Thank! But this only works after I release the mouse button. And how to make it so that when I pulled the mouse pointer, the values only changed according to the specified steps?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
it is impossible to make the slider move only in steps?
no?

Or in Java
B4X:
Slider slider = new Slider(1, 4, 1);
slider.setBlockIncrement(1);
slider.setMajorTickUnit(1);
slider.setMinorTickCount(0);
slider.setShowTickLabels(true);
slider.setSnapToTicks(true);

The key here is the snap to ticks option combined with a proper combination of tick units. This setting results in the following slider which can only be used to select values ranging from 1 to 4

 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
The problem is that if I use:
B4X:
Slider slider = new Slider(1, 4, 1);
slider.setBlockIncrement(1);
slider.setMajorTickUnit(1);
slider.setMinorTickCount(0);
slider.setShowTickLabels(true);
slider.setSnapToTicks(true);
When I lead a slider between 1 and 2, I get to Slider_ValueChange. And I wanted it to stick only in numbers 1,2,3,4
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
For your example in post#1 you could use the code below, Value is in 1/3 steps:

B4X:
Private Sub sldTest_ValueChange (Value As Double)
    Private intValue As Int
    intValue = Value * 3 + 0.5
    Value = intValue / 3
    lblValue.Text = NumberFormat(Value, 1, 2)
End Sub
 
Upvote 0
Top