NumberPicker icon indicating copy to clipboard operation
NumberPicker copied to clipboard

OnClick called as soon as the user touches

Open esuljic opened this issue 5 years ago • 0 comments

Background: I created CustomView with NumberPicker and EditText in the middle, and if the user clicks on NumberPicker, it shows the EditText with that value so the user can the value by the keyboard.

The problem is that onClickListener fires as soon as the user touches the middle number. The convention is that onClick should be called when the user lifts finger within getTapTimeout milliseconds.

I fixed it myself, but I would like you to integrate it into your library so I can continue using it.

My approach:

  1. Insert

private long clickedMillis = 0;

  1. Replace the 2 occurrences of:

if (mOnClickListener != null) { mOnClickListener.onClick(this); }

to:

clickedMillis = System.currentTimeMillis();

  1. Add this to ACTION_UP switch of onTouchEvent() method, when selectorIndexOffset == 0:

if (clickedMillis > System.currentTimeMillis() - ViewConfiguration.getTapTimeout() && mOnClickListener != null) { mOnClickListener.onClick(this); }

esuljic avatar Nov 29 '20 20:11 esuljic