No Double Click functionality? No Touch?

kcorey

Member
Licensed User
Longtime User
Looking at the tutorials, it says to explore the events you can respond to type "Sub", followed by a <space>, followed by a <tab>, and you'll be offered a set of objects that can receive events.

Select one of those, and you'll be showed the events that they can handle.

Most of the ones I looked at (button, ImageView) only have a 'click' handler built in.

What if I want to detect a double click, or a drag? How can I watch for touchStart and touchEnd and handle it in my code?

I saw a comment Erel made in 2008 saying that it's not possible to trap Doubleclicks...but have things moved on a bit?

-Ken
 

Informatix

Expert
Licensed User
Longtime User
Looking at the tutorials, it says to explore the events you can respond to type "Sub", followed by a <space>, followed by a <tab>, and you'll be offered a set of objects that can receive events.

Select one of those, and you'll be showed the events that they can handle.

Most of the ones I looked at (button, ImageView) only have a 'click' handler built in.

What if I want to detect a double click, or a drag? How can I watch for touchStart and touchEnd and handle it in my code?

I saw a comment Erel made in 2008 saying that it's not possible to trap Doubleclicks...but have things moved on a bit?

-Ken

The DoubleClick event does not exist at all on Android. To detect a double tap, you should calculate the elapsed time between the two clicks. If that's short enough, it's a double click.
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Yes, as @Informatix says, just detect the ticks every time in the _Click event and compare to the previous value.

You can do something like this:

B4X:
Dim lastValue, currentValue as Long

Sub btnA_Click

currentValue = DateTime.Now


if(currentValue - lastValue < DateTime.TICKS_PER_SECOND) Then ' check TICKS_PER_SECOND as I am not checking this code in the IDE
' fast click

Else
' slow click
End if

lastValue = currentValue

End Sub

Of course you should set some initial value to lastValue the first time(when it would be zero). I am giving this snippet out just for reference purposes.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
aw a comment Erel made in 2008 saying that it's not possible to trap Doubleclicks...but have things moved on a bit?
This comment was related to Basic4ppc (Windows Mobile) not Basic4android.

The native views do not expose a double click event as it is not a standard event in Android. As written above you can easily create such an event.
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
Can I get the source to the Gesture Library?

After a bit more research, it would seem that Double Touches /are/ a standard part of Android:

Gestures | Android Developers

...but they're described in the gestures documentation.

Is there any chance I could get the source to the Gestures library? I would like to add 'Double Touch' and maybe one or two other gestures to it...

-Ken
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
After a bit more research, it would seem that Double Touches /are/ a standard part of Android:

Gestures | Android Developers

...but they're described in the gestures documentation.

Is there any chance I could get the source to the Gestures library? I would like to add 'Double Touch' and maybe one or two other gestures to it...

-Ken

Thanks for the link. And sorry, I was wrong. But do you really need to edit the Gestures library for this ? It's so easy to do in plain Basic.
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
Not Really...

Well, no, I don't need to edit the Gestures library to implement this...but isn't that the right place in which to do it? Why hack it time and again, when it could be done (and easily, I'm thinking) properly?
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
If that were all...

It depends on what the first click does.

If the first click always just selects an item, and then the second click always takes an action, then you're right.

If the first click takes some action (drawing a card, say), and a double click takes a different action (as a contrived example, perhaps a double click passes without drawing a card)

Then you'd need to set up a timeout handler for a single click so that if the second click doesn't arrive before the timeout it's a single click. That's more than a 3 line addition, isn't it?

Additionally, I would also like to support dragging of the card as well as clicking.

Please correct me if I'm wrong, but I don't think that's provided out-of-the-box...which seems to say that I need to use the Gesture library.

If that's the case, why not put it in properly?

-Ken
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Instead of double click why not use longpress?

I use longpress on my custom menus which are just buttons on a panel and a single click does one thing but a longpress (less than a second of holding the button down) does something else.

I haven't looked at what other views can use this as my personal needs for my apps are fairly simple and don't involve graphics.

regards, Ricky
 
Upvote 0

kcorey

Member
Licensed User
Longtime User
Personal Preference

Why not long press?

Cause I don't like it, and I'm the dude with the compiler!

*grin*

Seriously, when I play a casual game like this, I get into a rhythm. Tap, tap, tap, tap, tap, tap.

A long tap breaks the rhythm: Tap, tap, tap, looooong tap, tap, tap.

See what I mean? Breaks the rhythm. It's a bit like chewing bubble gum and walking down the road at the same time: it just feels wrong.

-Ken

P.S. Still hoping someone can point me towards the source code for the gesture library...
 
Upvote 0

antonomase

Active Member
Licensed User
Longtime User
Yes, as @Informatix says, just detect the ticks every time in the _Click event and compare to the previous value.

You can do something like this:
...

You source code doesn't switch beetween double click and single click. The first time, it always runs single click (currentValue - lastValue > ....).
And at the second click, it runs the double click.

The code for a real switch between single and double click would be :
1) at the first click, store the time but do nothing
2) wait during x milliseconds or until a second click is detected
if a second click is detected, --> double click
if the waiting time is over --> single click
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
You source code doesn't switch beetween double click and single click. The first time, it always runs single click (currentValue - lastValue > ....).
And at the second click, it runs the double click.

The code for a real switch between single and double click would be :
1) at the first click, store the time but do nothing
2) wait during x milliseconds or until a second click is detected
if a second click is detected, --> double click
if the waiting time is over --> single click
You replied to an old thread. And your solution is not complete: for a valid double tap, you have to check that the second click occurs in the same area of the first click (except if you want to detect two clicks in a row and not the double tap gesture). It's a lot easier to let the Gesture Detector library do the job for you.
 
Upvote 0

antonomase

Active Member
Licensed User
Longtime User
1) Old threads are not dead threads. It is not abnormal to indicate that a source code is wrong for people who read this thread.
2) my indications are not a solution, just indications
 
Upvote 0
Top