LongClick事件也触发Click事件 [英] LongClick event also triggers Click event
问题描述
我用一个按钮onLongClick和的onClick事件来获取用户输入。每当;用户长按并触发onLongClick事件,onClick事件也被触发。我找不到我的问题。两种方法的code的示于下面:
I use onLongClick and onClick events of a button to get user inputs. Whenever; the user long click and triggers onLongClick event, the onClick event is also triggered. I couldn't find my problem. The code of two methods are shown in below:
@Override
public void onClick(View v) {
switch(((Button) v).getId())
{
case R.id.enter:
EntertheNumber();
break;
case R.id.clear:
CleartheNumber();
break;
case R.id.number_zero:
case R.id.number_one:
case R.id.number_two:
case R.id.number_three:
case R.id.number_four:
case R.id.number_five:
case R.id.number_six:
case R.id.number_seven:
case R.id.number_eight:
case R.id.number_nine:
AddtotheNumber(mEditor, (Button) v);
break;
}
@Override
public boolean onLongClick(View view) {
if(SMBGuesstheNumber.bDisplayFlagList)
{
theActiveButton = (Button) view;
showDialog(R.id.display_flaglist);
}
return false;
}
其实,我的项目是开源的。 //$c$c.google.com/p:所以,你可以在 HTTP发现所有的code / guessthenumber /
感谢你。
推荐答案
我不知道什么样的顺序发生这些事件,而是onLongClick处理程序返回一个布尔值,指示该事件是否已被处理。如果你处理它,以便其他点击事件将不会被调用,你应该返回true。我不知道这是否会prevent prevent onClick的()烧制而成,虽然。
I'm not sure what order these events occur but the onLongClick handler returns a bool to indicate whether the event was handled. You should return true if you handled it so that other click events will not be called. I don't know if this will prevent prevent the onClick() from firing though.
您也可以把这些事件关闭和使用setClickable(布尔)和setLongClickable(布尔)
You may also turn these events off and on using setClickable(boolean) and setLongClickable(boolean)
您可以找到此信息,更多的是UI事件这里。
You can find this information and more about UI events here.
这篇关于LongClick事件也触发Click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!