LongClick event also triggers Click event

后端 未结 3 524
失恋的感觉
失恋的感觉 2021-02-13 10:03

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\

相关标签:
3条回答
  • 2021-02-13 10:35

    here is a brief summary regarding touch event: http://rxwen.blogspot.com/2010/10/android-touch-event-summary.html

    0 讨论(0)
  • 2021-02-13 10:47

    Solution On LongClick SingleClick will not work :

    rippleView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                //Your code
                }
            });
    rippleView.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    return true;
                }
            });
    
    0 讨论(0)
  • 2021-02-13 10:52

    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.

    You may also turn these events off and on using setClickable(boolean) and setLongClickable(boolean)

    You can find this information and more about UI events here.

    0 讨论(0)
提交回复
热议问题