3

How to make EditText Field uneditable over property inputType when

inputType="textPassword"

My problem is that following code line makes the password visible.

password.setInputType(InputType.TYPE_NULL);

Already tried following, but remains editable

password.setEnabled(false)
endian
  • 4,761
  • 7
  • 32
  • 54

2 Answers2

3

If you play with :

edittext.setFocusable();
edittext.setFocusableInTouchMode();

You should be able to make the EditText editable/uneditable when you want.

Jeremy D
  • 4,787
  • 1
  • 31
  • 38
2

Using this: How to make EditText not editable through XML in Android?

You said that you wanted your field to be editable after some logic. Do this:

KeyListener keyLis = textView.getKeyListener();
textView.setKeyListener(null);

Then, when you want your TextView to be editable again, do this:

textView.setKeyListener(keyLis);

Documentation for TextView class:

Two methods:

getKeyListener()

setKeyListener(KeyListener keyLis)

EDIT

I didn't find any beautiful answers, but I did find a few alternative ways to do this:

  1. To make uneditable

    valueText.setEnabled(false); valueText.setClickable(false); valueText.setFocusable(false);

And then,

valueText.setEnabled(true);
valueText.setClickable(true);
valueText.setFocusable(true);
  1. You can also change what happens when the text is edited to make nothing happen: Can we have uneditable text in edittext

    1. There are some other very wild solutions, out there. They're not beautiful at all, though.

I recommend using the initial solution, unless somebody finds a quicker way.

Sorry I couldn't find a better way to do this :(

Community
  • 1
  • 1
eboix
  • 5,113
  • 1
  • 27
  • 38