Android Question Bug in B4A Fluidslider No Wrap

mcqueccu

Well-Known Member
Licensed User
Longtime 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

Iu8Ycbw.gif
 

Attachments

  • fluidslider.gif
    fluidslider.gif
    92.7 KB · Views: 373

Peter Simpson

Expert
Licensed User
Longtime User
Don't worry about the warning, you can post an apparent error on the original post for the author to look at.

Anyway the slider is working on my test device, double check your label code and add Min/Max if you have to...
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime 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:
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime 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
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime 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...
 
Upvote 0

MbedAndroid

Well-Known Member
Licensed User
Longtime 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)
 
Upvote 0
Top