Android Question Changing LongClick delay?

klaus

Expert
Licensed User
Longtime User
I don't know if you can change the long click duration for a button.

But you can do it with the Touch event.
For a Panel you can use it's B4A Touch event routine.
For a Button you need to set the SetOnTouchListener with the reflection library.
The attached test program shows the routines for both a Panel and a Button.
The routine for the Button could be used for any other view.

In Activity_Create:
B4X:
Private refbtnTest As Reflector
refbtnTest.Target = btnTest
refbtnTest.SetOnTouchListener("btnTest_Touch")
The routine for the Button:
B4X:
Sub btnTest_Touch (ViewTag As Object, Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Private v As View
    v = Sender
  
    Select Action
    Case Activity.ACTION_DOWN
        Time0 = DateTime.Now
        Activity.Title = "Down"
    Case Activity.ACTION_MOVE
        Activity.Title = "Move"
    Case Activity.ACTION_UP
        Activity.Title = "Up"
        If X > 0 And X < v.Width And Y > 0 And Y < v.Height Then
            If DateTime.Now - Time0 > LongClickTime Then
                ToastMessageShow("Button LongClick", False)
            Else
                ToastMessageShow("Button Click", False)
            End If
        End If
    End Select
    Return True    'Consumes the event
End Sub
 

Attachments

  • Touch_LongClick.zip
    7.4 KB · Views: 195
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
I am using this example "Touch_LongClick" to create a LongClick event of 3 seconds.
However, irrespective of the "LongClickTime" I set, I always receive:
ToastMessageShow("Button Click", False).
It seems that the:
B4X:
If DateTime.Now - Time0 > LongClickTime Then
is never called.
I am using Android 5.1
 
Upvote 0
Top