Android EditText setOnClickListener

android, android-edittext, java

Solution

As others have said, the first touch focuses the view, the second touch "clicks" it. Instead of implementing `OnClickListener`, implement `OnFocusChangeListener`. e.g.

EditText edittext = (EditText)findViewById(R.id.myedittext);
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean hasFocus) {
        if(hasFocus) {
            //handle your situation here
        }
    }
});

Problem

I have an EditText field. When I set onClickListener on it, it will require first the focus on the field and then the click to call the listener. So it's actually two clicks to call the listener. How can I fix this to work from the first click? I don't want to set focusable to false because then the program won't work.

Original source