B4J Question ClickCount behavior

a n g l o

Active Member
Licensed User
Longtime User
hello,
dblClick fires both subs.
i need it to do something else then click.

B4X:
Sub btn_MouseClicked (EventData As MouseEvent)
        If EventData.ClickCount=1 Then
                subA
        Else if EventData.ClickCount=2 Then
                subB
        End If
End Sub

Sub subA
        Log("in subA")
End Sub

Sub subB
        Log("in subB")
End Sub[/CODE


i know i can add a timer to wait for another click (or not)... but maybe i'm missing something here....
Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Double clicking on a button is not a common UX.
However, here is a solution based on the index pattern:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    Private Button1Index As Int
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Private Sub Button1_MouseClicked (EventData As MouseEvent)
    Button1Index = Button1Index + 1
    If EventData.ClickCount > 2 Then Return
    If EventData.ClickCount = 1 Then
        Dim MyIndex As Int = Button1Index
        Sleep(300)
        If MyIndex <> Button1Index Then Return
    End If
    Log(EventData.ClickCount)
End Sub

[B4X] Resumable subs and the index pattern
 
Upvote 0

a n g l o

Active Member
Licensed User
Longtime User
Thank You ! that's a solution.
actually i've tested that on other views besides button getting same behavior.
my opinion is that it should somehow find its way to next version fixes so the above solution will be hidden behind :).
Thanks again.
 
Upvote 0
Top