我試過以下代碼來區分單擊和雙擊。單擊即可。當我雙擊imageview時,單擊和雙擊部分內的代碼都會執行。區分單擊並雙擊androidView中的imageView
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;
}
在你的代碼中我可以放單和雙擊代碼? – Manikandan
@Manikandan我編輯答案。重新檢查。 –
我用你的代碼,當我雙擊時,單擊內的代碼也執行 – Manikandan