Android Question Bug in B4A Fluidslider No Wrap

mcqueccu

Well-Known Member
Licensed User
I realised the Fluidslider here goes beyond the Max and Min Limit. Even though its label stops at the min and max value, value still increases when you continue to hold the slider when it reaches the ends.

Note: Its same example provided, i just added the label to display the values and reduced the width of the slider

 

Attachments

mcqueccu

Well-Known Member
Licensed User
You should have put this post on the original thread...
Forum Rule: Don't bump old thread....

There was a warning about the thread being Old (More than 1 Month) that is why I created this new one
 

Peter Simpson

Expert
Licensed User
@mcqueccu What device are you using, also what happens if you replace the original sub with this sub, does it make any difference to you?
B4X:
Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case 0 ' ACTION_DOWN
            Dim P As Int = ((X / mBase.Width) * (MaxValue - MinValue)) + MinValue
            setValue(P, True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 1 ' ACTION_UP
            Ball.SetLayoutAnimated(200, Ball.Left, mBase.Height / 2, mBase.Height / 2, mBase.Height / 2)
        Case 2 ' ACTION_MOVE
            Dim P As Int = ((X / mBase.Width) * (MaxValue - MinValue)) + MinValue
            If P < 0 Then P = 0 : If P > 100 Then P = 100
            setValue(P, True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 3 ' Error
    End Select
End Sub
Enjoy...
 
Last edited:

mcqueccu

Well-Known Member
Licensed User
The solution above works perfectly if you are selecting between 0 and 100.
But if you set your Minimum Value say 10, and maximum value say 91, the slider still goes to 0 or to 100 irrespective of the Limits.

This Now works for me:

B4X:
Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case 0 ' ACTION_DOWN
            Dim P As Int = ((X / mBase.Width) * (MaxValue  -MinValue)) + MinValue
          '  If P < 0 Then P  =0 : If P > 100 Then P = 100
              If P<MinValue Then p = MinValue : If p > MaxValue Then p = MaxValue '<-----------------------------
            setValue(P,True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 1 ' ACTION_UP
            Ball.SetLayoutAnimated(200, Ball.Left, mBase.Height/2, mBase.Height/2, mBase.Height/2)
        Case 2 ' ACTION_MOVE
            Dim P As Int = ((X / mBase.Width) * (MaxValue - MinValue)) + MinValue
            'If P<0 Then P=0 : If P> 100 Then P=100
            If P<MinValue Then p = MinValue : If p > MaxValue Then p = MaxValue    '<-----------------------------
            setValue(P,True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 3 ' Error
    End Select
End Sub
 

Peter Simpson

Expert
Licensed User
Here you go @mcqueccu , the following code covers all set ranges, you can completely remove one of the lines.
B4X:
Private Sub Panel_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        Case 0 ' ACTION_DOWN
            Dim P As Int = ((X / mBase.Width) * (MaxValue - MinValue)) + MinValue
            'If P < 0 Then P = 0 : If P > 100 Then P = 100
            setValue(P, True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 1 ' ACTION_UP
            Ball.SetLayoutAnimated(200, Ball.Left, mBase.Height / 2, mBase.Height / 2, mBase.Height / 2)
        Case 2 ' ACTION_MOVE
            Dim P As Int = ((X / mBase.Width) * (MaxValue - MinValue)) + MinValue
            If P < MinValue Then P = MinValue : If P > MaxValue Then P = MaxValue
            setValue(P, True)
            If SubExists(mCallBack, mEventName & "_ChangeValue") Then CallSub2(mCallBack, mEventName & "_ChangeValue", p)
        Case 3 ' Error
    End Select
End Sub
Enjoy...
 

MbedAndroid

Active Member
Licensed User
added my cent:
use it when the ball is released to store the final result to the database....

B4X:
Case 1 ' ACTION_UP
            
            Ball.SetLayoutAnimated(200,Ball.Left,mBase.Height/2,mBase.Height/2,mBase.Height/2)
            Private p=getValue As Int
            If SubExists(mCallBack,mEventName & "_KeyUp") Then CallSub2(mCallBack,mEventName & "_KeyUp",p)
 
Top