Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnClick called as soon as the user touches #183

Open
esuljic opened this issue Nov 29, 2020 · 0 comments
Open

OnClick called as soon as the user touches #183

esuljic opened this issue Nov 29, 2020 · 0 comments

Comments

@esuljic
Copy link

esuljic commented Nov 29, 2020

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 esuljic changed the title OnClick called as soon as user touches OnClick called as soon as the user touches Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant