Java – OnClickListener does not work when editing text is disabled

OnClickListener does not work when editing text is disabled… here is a solution to the problem.

OnClickListener does not work when editing text is disabled

I have an edittext View in my Android app. For free users, I want to disable edittext View and when the user clicks on it, I want to display the toast.
I have managed to disable editing with the following code

text_status1.setEnabled(false);

But now my setOnClickListener doesn’t work either. Can anyone help me get it to work when edittext is disabled?

Thanks

Solution

Use setFocusable instead of setEnabled :

  EditText some = mView.findViewById(R.id.some);
    some.setFocusable(false);
    some.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.out.println("your View got clicked");
        }
    });

By using setFocusable false, the user can perform a click on the View, but he cannot get the focus needed to edit the editText

Related Problems and Solutions