10

If I disable an EditText widget using

editText.setEnabled(false);

I can still type into it using the on-screen input method (in both the emulator and on the G1). Is this intended? How can I workaround this issue?

Josef Pfleger
  • 72,585
  • 15
  • 95
  • 99

7 Answers7

9

I notice that you can't activate the on-screen keyboard by tapping on a disabled EditText, and also the DEL key doesn't work, so this looks like a bug to me. I filed it as issue 2771 in the Android issue tracker.

Jon Colverson
  • 2,678
  • 1
  • 21
  • 23
6
edittext.setKeyListener(null);

This will help you

shanethehat
  • 15,105
  • 10
  • 54
  • 84
SKT
  • 1,761
  • 1
  • 19
  • 30
2

Use this, it worked for me

setFocusableInTouchMode(boolean);

setFocusable(boolean);
Lucifer
  • 28,605
  • 21
  • 86
  • 137
subair_a
  • 956
  • 2
  • 13
  • 18
1

I fixed this issue but the patch only got included in Honeycomb. That's why I've created a little project which will contain my backported fixes to versions starting from 2.1. It contains the fix for bug 2771: http://code.google.com/p/android-fixes/
You can check out the "library" from the svn and include it in your project. Then instead of android.widget.EditText import edu.ubbdroid.android.widget.EditText (which extends the original EditText) and the problem should be gone :)

1
etComment.setEnabled(flag);
etComment.setFocusable(flag);
etComment.setFocusableInTouchMode(flag);
if (flag) {
    etComment.requestFocus();
}
etComment.setFilters(new InputFilter[] { new InputFilter() {
    @Override
    public CharSequence filter(
        CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (!flag) {
                return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
            }
            return null;
        }
    }
});

for all you can got it!

Manoj Sharma
  • 1,467
  • 2
  • 12
  • 20
user651093
  • 11
  • 1
1

Perhaps You could alternatively dynamically substitute with TextView and back. But You would probably need to adjust font to match the EditText.

KarolDepka
  • 7,188
  • 9
  • 37
  • 55
0

I think you should be able to editText.setOnClickListener() with your own function and call super.onClickListener() if you want your text edited.

Edit:
Following link has some answers which sound more like the right way:
Can we have uneditable text in edittext

Community
  • 1
  • 1
buster
  • 786
  • 1
  • 7
  • 12
  • I know, I provided one of the answers there :) This question is not about *how* to make it non-editable but *why* setEnabled(false) would still allow modifications. I was wondering whether I got the widget-enabled concept wrong. – Josef Pfleger May 26 '09 at 19:46