Skip to content

OnClick called as soon as the user touches #183

Description

@esuljic

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions