In the layout you can set the EditText
widget to be non-editable via the android:editable attribute
.
How can I do this in code? I need to make the EditText
widget to be editable depending on conditions.
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.
Use this code: editText. setEnabled(false); editText.
If you set android:editable="true" you can access the TextView via the D-pad, or you could add android:focusableInTouchMode="true" to be able to gain focus on touch. The problem is you cannot modify the existing text, and you cannot move the cursor. The text you write just gets added before the existing text.
editText.setFocusable(false); editText.setClickable(false);
this ensure the EditText
control can't be selected and focused, so it can't be edited.
I just tried this myself,
To disable editing text:
.setFocusable(false);
this also sets setFocusableInTouchMode to false!
To enable editing text:
setFocusableInTouchMode(true);
this also sets setFocusable to 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