Android: Why does long click also trigger a normal click?

前端 未结 4 1125
一整个雨季
一整个雨季 2020-12-01 00:40

I have a ListView with listeners for a long click and a regular click.

Why, when I long press a list item, the regular click event gets called too?

I need to

4条回答
  •  不思量自难忘°
    2020-12-01 00:58

    Restating the answer in simpler terms:

    Given:

    @Override
    public boolean onLongClick(View view) {
    
        return true; // or false
    }
    
    • return true means that the event is consumed. It is handled. No other click events will be notified.
    • return false means the event is not consumed. Any other click events will continue to receive notifications.

    So if you don't want onClick to also be triggered after an onLongClick, then you should return true from the onLongClick event.

提交回复
热议问题