Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a double touch/taps on an Android ListView?

Tags:

android

Do you know about how to detect two touches/taps on a ListView?

I am trying to have the following method called when double touched:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
}

Thanks in advance.

like image 395
AndroiDBeginner Avatar asked Dec 26 '09 08:12

AndroiDBeginner


4 Answers

Why aren't you using a Long Touch? Or are you using that already for something else? The advantages over a long touch over a double touch:

  • Long Press is a recommeded interaction in the UI Guidelines, double touch is not.
  • It's what users expect; a user might not find a double touch action as they won't go looking for it
  • It's already handled in the API.
like image 107
Dave Webb Avatar answered Nov 12 '22 04:11

Dave Webb


Edit:

See it here: Involving CountDownTimer: https://github.com/NikolaDespotoski/DoubleTapListView Involving Handler: http://code.google.com/p/double-tap-listview-handler/ https://github.com/NikolaDespotoski/DoubleTapListViewHandler My brief explaination: http://mobisys.in/blog/2012/01/how-to-detect-double-taps-on-listview-items-in-android/

like image 2
Nikola Despotoski Avatar answered Nov 12 '22 03:11

Nikola Despotoski


If you are set on using a double tap in your UI, you could always save state in your Actvity or other container.

A simple implementation would be storing the time the touch was registered, and comparing against that on the next touch event to determine if the time lapsed since the second touch falls with in whatever range you are defining a double tab to mean.

like image 1
k_day Avatar answered Nov 12 '22 03:11

k_day


I think that a double tap on a ListView can be totally valid, particularly if it is done over an unoccupied area. For instance I have a diary application listing actions for today. This is already so that long presses allow actions to be edited or deleted. But left / right touch gestures are used to quickly move to the previous / next day, and a double tap is a shortcut to get back to "today". Is that intuitive? Well, close enough, I think.

like image 1
micrometal Avatar answered Nov 12 '22 02:11

micrometal