Search code examples
androidandroid-edittextonclicklistener

Is there a way to reset the OnClickListener to its default Android implementation?


I have an editText to which I have set an OnClickListener, which is set to open a Dialog. But I have an option in the Dialog to let the user enter data into the editText by manually typing. I tried calling setOnClickListener(null), but it makes the editText unresponsive.

As of yet I have tried a lot of things, but the only thing that works is recreating the activity by calling recreate(), but I'd rather the user not know that I'm recreating the Activity. How do I reset the editText to behave normally like an Android editText works? (like opening the keyboard and entering data on tapping it)


Solution

  • Change

     editText.setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //do as u wish
                        }
                    }
            );
    

    to

      editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if(hasFocus){
    //                        do as you wish
                    }
                }
            });