B4J Question Slider Values Changed

red30

Well-Known Member
Licensed User
Longtime User
How can I get the values from the slider after releasing the mouse button? Released callback, called when the slider is released. Now while I move the slider my program always hangs in Slider_ValueChange.
 

red30

Well-Known Member
Licensed User
Longtime User
Not in the sense of freezes. Just constantly go there when I move the slider. I would like the program to go to Slider_ValueChange after the slider value is set.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Instead of the sub
B4X:
Sub Slider1_ValueChange (Value As Double)
    
End Sub

Use

B4X:
Sub Slider1_MouseReleased (EventData As MouseEvent)
    Log("Slider Val " & Slider1.Value)
End Sub
 
Upvote 0

red30

Well-Known Member
Licensed User
Longtime User
Instead of the sub
B4X:
Sub Slider1_ValueChange (Value As Double)
   
End Sub

Use

B4X:
Sub Slider1_MouseReleased (EventData As MouseEvent)
    Log("Slider Val " & Slider1.Value)
End Sub
And if I want to release the mouse button and use the keyboard?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Global var - SliderMousePressed As Boolean


B4X:
Private Sub Slider1_MousePressed (EventData As MouseEvent)
    SliderMousePressed = True
End Sub

Private Sub Slider1_ValueChange (Value As Double)
    If SliderMousePressed Then Return
    Slider1_DOValueChanged
End Sub

Private Sub Slider1_MouseReleased (EventData As MouseEvent)
    SliderMousePressed = False
    Slider1_DOValueChanged
End Sub

Private Sub Slider1_DOValueChanged
    Log("Value Changed " & Slider1.Value)
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Different approach:
B4X:
Sub Slider1_ValueChange (Value As Double)
   Slider1Index = Slider1Index + 1
   Dim MyIndex As Int = Slider1Index 'Slider1Index is a global Int variable
   Sleep(300)
   If MyIndex = Slider1Index Then
       Log("New value: " & Value)
       'do anything you like here      
   End If
End Sub

The behavior is not exactly the same. It updates after the slider was idle for 300ms.
 
Upvote 0
Top