Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EditText non editable

I'm trying to make an EditText non editable with this code:

<EditText android:id="@+id/outputResult"           android:inputType="text"           android:editable="false"           android:layout_width="fill_parent"           android:layout_height="wrap_content"           android:text="@string/result" /> 

I had to add following line to make it non-editable

android:focusable="false"  

Am I doing something wrong?

like image 624
Jjreina Avatar asked Feb 27 '12 18:02

Jjreina


People also ask

How do you make EditText not editable?

Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.

Is EditText deprecated?

Android Studio:EditText editable is deprecated How to use inputType.

How do I turn an editable into a string?

Simply use toString() on the Editable instance to get String.


1 Answers

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.yourid); mEdit.setEnabled(false); 

This is also a viable alternative :

EditText mEdit = (EditText) findViewById(R.id.yourid); mEdit.setKeyListener(null); 

If you're going to make your EditText non-editable, may I suggest using the TextView widget instead of the EditText, since using a EditText seems kind of pointless in that case.

EDIT: Altered some information since I've found that android:editable is deprecated, and you should use android:inputType="none", but there is a bug about it on android code; So please check this.

like image 76
Jean-Philippe Roy Avatar answered Sep 17 '22 04:09

Jean-Philippe Roy