Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replicate android:editable="false" in code?

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.

like image 835
AngryHacker Avatar asked Mar 18 '09 21:03

AngryHacker


People also ask

How do you set editable false in android programmatically?

In your xml code set focusable="false" , android:clickable="false" and android:cursorVisible="false" and this will make your EditText treat like non editable.

How do you make text not editable on android?

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.

How do you make Uneditable text edits?

Use this code: editText. setEnabled(false); editText.

How do you use editable text on android?

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.


2 Answers

editText.setFocusable(false); editText.setClickable(false); 

this ensure the EditText control can't be selected and focused, so it can't be edited.

like image 51
Gerry Avatar answered Oct 09 '22 13:10

Gerry


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;

like image 26
atpanos Avatar answered Oct 09 '22 12:10

atpanos