How to capture onclick event in disabled EditText in Android App

AndroidOnclickAndroid Edittext

Android Problem Overview


I have a EditText which I am presenting as disabled so that user cannot edit the contents and also to avoid popping-up keyboard. But now I want to capture onclick event in the EditText and identify the individual words that are being clicked. Any help is most welcome.

Thanks, Balkrishna.

Android Solutions


Solution 1 - Android

On your EditText set attributes android:focusable="false" and android:enabled="true". And set OnClickListener to that EditText. The click on that Edittext triggers the onClick() method but it can't be edited. I just tried it.

Solution 2 - Android

You can make the component unclickable by using.

editText.setClickable(false);

To make the component look visually disabled by decreasing the Alpha value.

editText.setAlpha(0.5f);

It will allow you to set an OnTouchListener on your component by which you can perform your desired operations.

editText.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        Toast.makeText(getApplicationContext(),"Component is disabled", Toast.LENGTH_SHORT).show();
                        return false;
                    }
                });

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBalkrishna RawoolView Question on Stackoverflow
Solution 1 - AndroidRajkiranView Answer on Stackoverflow
Solution 2 - AndroidOmer ShafiqView Answer on Stackoverflow