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.
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