We can set editable property of EditText
in XML layout but not programatically, but there is no setEditable()
method!
If EditText
is not Enabled [ by setEnabled(false)
] it still Editable!
In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.
android:editable="false" should work, but it is deprecated, you should be using android:inputType="none" instead. Alternatively, if you want to do it in the code you could do this : EditText mEdit = (EditText) findViewById(R. id.
For the above requirement the solution in XML is android:editable="false" but I want to use this in Java. et. setKeyListener(null); It makes the EditText not EDITABLE but at the same time it makes it non clickable as well.
Simply use toString() on the Editable instance to get String.
This may help:
if (cbProhibitEditPW.isChecked()) { // disable editing password
editTextPassword.setFocusable(false);
editTextPassword.setFocusableInTouchMode(false); // user touches widget on phone with touch screen
editTextPassword.setClickable(false); // user navigates with wheel and selects widget
isProhibitEditPassword= true;
} else { // enable editing of password
editTextPassword.setFocusable(true);
editTextPassword.setFocusableInTouchMode(true);
editTextPassword.setClickable(true);
isProhibitEditPassword= false;
}
I did it in a easier way , setEditable and setFocusable false. but you should check this.
How to replicate android:editable="false" in code?
Fetch the KeyListener value of EditText
by editText.getKeyListener()
and store in the KeyListener type variable, which will contain
the Editable property value:
KeyListener variable;
variable = editText.getKeyListener();
Set the Editable property of EditText
to false as:
edittext.setKeyListener(null);
Now set Editable property of EditText
to true as:
editText.setKeyListener(variable);
Note: In XML the default Editable property of EditText
should be true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With