Android Question [Solved]Twice Responsed when Click event

Theera

Expert
Licensed User
Longtime User
I have learned creating a B4X Customview,I have error when I clicked the button,it run MsgboxAsync() 2 times.
I don't know how to clear clicked only 1 time.
B4X:
Private Sub pnl_Touch (Action As Int, X As Float, Y As Float)
    If mDisabled Then Return
    
    Dim Inside As Boolean
    ' For a circular button, calculate if X, Y is within the circle's radius.
    Dim centerX As Float = mBase.Width / 2
    Dim centerY As Float = mBase.Height / 2
    Dim radius As Float = Min(mBase.Width, mBase.Height) / 2 - mBorderWidth
    Inside = Power(X - centerX, 2) + Power(Y - centerY, 2) < Power(radius, 2)
    
    Select Action
        Case mBase.TOUCH_ACTION_DOWN
            If Inside Then  ' เช็คว่าอยู่ในขอบเขตก่อน
                SetPressedState(True)
                Draw
            End If
        Case mBase.TOUCH_ACTION_MOVE
            If pressed <> Inside Then
                SetPressedState(Inside)
                Draw
            End If
        Case mBase.TOUCH_ACTION_UP, 3
            Dim wasPressed As Boolean = pressed
            SetPressedState(False)
            Draw
            ' ส่ง Click event เฉพาะเมื่อ touch ขึ้นภายในขอบเขตและเคยกดลง
            If Inside And wasPressed Then
                Log("Button clicked!")  ' เพิ่ม log เพื่อ debug
                If mHaptic Then XUIViewsUtils.PerformHapticFeedback(mBase)
                CallSubDelayed(mCallBack, mEventName & "_Click")
            End If
    End Select
End Sub
 

Theera

Expert
Licensed User
Longtime User
Ok,I have resolved it. It has 2 events (button_clicked and mouse_clicked),so I added #If B4A..EndIf Block.
 
Upvote 0
Solution

Theera

Expert
Licensed User
Longtime User
Don't use MsgboxAsync to debug your program. Use Log instead.

Your code looks similar to SwiftButton from XUI Views, which is a good thing. The event shouldn't be raised multiple times when the button is clicked. The problem is somewhere else.
Yes,Sir. I have learned the code from yours. Thank you for your code.
 
Upvote 0
Top