LongClick事件也触发Click事件 [英] LongClick event also triggers Click event

查看:250
本文介绍了LongClick事件也触发Click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用onLongClick和onClick事件来获取用户输入。每当;用户长时间点击并触发onLongClick事件,onClick事件也被触发。我找不到我的问题两种方法的代码如下所示:

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;
    }

其实我的项目是开源。因此,您可以在 http://code.google.com/p/guessthenumber/

Actually, my project is Open Source. So, you can find all the code at http://code.google.com/p/guessthenumber/

谢谢。

推荐答案

我不是确定这些事件发生的顺序,但是onLongClick处理程序返回一个bool来指示事件是否被处理。如果您处理它应该返回true,以便不会调用其他点击事件。我不知道这是否会阻止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(boolean)和setLongClickable( boolean)

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆