Unable to disable long click on an editText

5.2k views Asked by At

I have an EditText on which I need to disable long click. On long clicking the editText the action mode set for the apps WebView pops up.

Tried adding the below code but failed.

editTextView.setLongClickable(false);
editTextView.setTextIsSelectable(false);

Also tried adding

longClickable="false"

on the layout xml.

2

There are 2 answers

0
TWL On

I don't know about you, but a simple editText.setLongClickable(false); works as expected.

You may have some other method or xml overriding it, for example:

    // example 1
    editText.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            return false;
        }
    });
    editText.setLongClickable(false);

is not the same as:

    // example 2
    editText.setLongClickable(false);
    editText.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            return false;
        }
    });

In example 1, editText's long-click will be disabled.

In example 2, editText's long-click is still enabled.

These are just java examples, there can also be xml elements to check for.

You need to check your flow or post more code.

0
Rakshit Nawani On

Try using

editTextView.setFocusableInTouchMode(false);

OR

editTextView.setClickable(false);
editTextView.setFocusable(false);