I have tried the following code to differentiate single click and double click. Single click is ok. When I double click the imageview, code inside both the single click and double click part execute.
private static final long DOUBLE_PRESS_INTERVAL = 250; // in millis
private long lastPressTime;
boolean mHasDoubleClicked;
img_feat_orgn_item.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
findDoubleClick();
}
});
private boolean findDoubleClick() {
// Get current time in nano seconds.
long pressTime = System.currentTimeMillis();
// If double click...
if (pressTime - lastPressTime <= DOUBLE_PRESS_INTERVAL) {
mHasDoubleClicked = true;
startActivity(new Intent(
Wv_HomePage.this,
NewDonation.class));
// double click event....
} else { // If not double click....
mHasDoubleClicked = false;
Handler myHandler = new Handler() {
public void handleMessage(Message m) {
boolean mHasDoubleClicked = false;
if (!mHasDoubleClicked) {
// single click event
feature_class_val = listData_Feature_Organization
.get(j);
Intent intent = new Intent(
Wv_HomePage.this,
OrganizationDetails.class);
Bundle b = new Bundle();
b.putString("orgn_name",
feature_class_val.name);
intent.putExtras(b);
startActivity(intent);
}
}
};
Message m = new Message();
myHandler.sendMessageDelayed(m, DOUBLE_PRESS_INTERVAL);
}
lastPressTime = pressTime;
return mHasDoubleClicked;
}
Try this.
Or you can check DOUBLE-TAP example from following URL. that is used in listView. i hope it is useful for you.
https://nodeload.github.com/NikolaDespotoski/DoubleTapListView/zip/master
By convention, Android apps don't have double clicking.
Maybe you'd rather use onLongClick?
Although, if you really want double click check out GestureDetector.OnDoubleTapListener
Here's my code, which seem to work.
just a little change and my code works fine. I placed the mHasDoubleClicked boolean inside handler, that makes the trouble. The below code works.