Is there any way of using LongClick and Touch events together?

ozgureffe

Member
Licensed User
Longtime User
Is there any way of using LongClick and Touch events together on the same object?
 

MrKim

Well-Known Member
Licensed User
Longtime User
Yes:
B4X:
Sub Panel1_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
   Log(x)
   Return False
End Sub
Sub Panel1_LongClick
   Log("long")
End Sub

I tried this and it does not seem to work. The LongClick event does not happen as soon as I add a Touch event Even with Return False.
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
I'm afraid that this thread is outdated because the 'standard' Touch event has no return variable anymore.
But you can handle a kind of LongClick event in the Touch event routine.
B4X:
Sub Globals
    Dim pnlTest As Panel
    Dim Time0 As Long
    Dim x0, y0 As Float
    Dim LongClickTime = 500 As Long
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlTest.Initialize("pnlTest")
    Activity.AddView(pnlTest, 0, 0, 100%x, 100%y)
End Sub

Sub pnlTest_Touch (Action As Int, X As Float, Y As Float)
    Select Action
    Case Activity.ACTION_DOWN
        Time0 = DateTime.Now
        x0 = X
        y0 = Y
        Activity.Title = "Down"
    Case Activity.ACTION_MOVE
        Activity.Title = "Move"
    Case Activity.ACTION_UP
        If DateTime.Now - Time0 > LongClickTime AND X - x0 < 10dip AND Y - y0 < 10dip Then
            Activity.Title = "LongClick"
        Else
            Activity.Title = "Up"
        End If
    End Select
End Sub

Attached a small test program.

Best regards.
 

Attachments

  • Touch_LongClick.zip
    6 KB · Views: 385
Upvote 0
Top