在我的应用程序中,我需要同时使用onClick
和contextmenu
进行单一视图工作正常但如果我长时间点击上下文菜单,我无法在特定视图上执行onclick。请任何人帮我解决这个问题。
答案 0 :(得分:2)
也许你可以使用onTouch insteed吗?
protected boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
long past;
long now;
switch (action) {
case MotionEvent.ACTION_DOWN:
past = System.currentTimeMillis();
// do nothing here
case MotionEvent.ACTION_UP:
now = System.currentTimeMillis();
if (now - past < 3000) {
// a click, do what ever you want here
}
else if (now - past >= 3000) {
// longclick, do what ever you want here
}
}
return false;
}