Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an EditText uneditable/disabled

I have a EditText in which the user should not be able to provide input. So I tried disabling it,by

edittext.setEnabled(false); edittext.setClickable(false); 

But still when I press the "next" button in the softKeyboard from some other EditText it directs me to the one which should not be editable and I am able to insert values into it. How to avoid this?

like image 645
Andro Selva Avatar asked Jul 18 '11 09:07

Andro Selva


People also ask

How do you make EditText not editable and clickable?

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.

How do I make EditText disabled?

To disable an EditText while keeping this properties, just use UI. setReadOnly(myEditText, true) from this library.

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.

Which of the following is the correct code for disabling and EditText?

setEnabled(false); , in combination with editText. setFocusable(false); will achieve this. The same works with XML: android:enabled="false" and android:focusable="false" . Thanks guys!


1 Answers

This works fine; just set focusable property of your edittext to "false" and you are done.

<EditText         android:id="@+id/EditTextInput"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:focusable="false"         android:gravity="right"         android:cursorVisible="true">     </EditText> 
like image 192
Khurram Shehzad Avatar answered Sep 27 '22 23:09

Khurram Shehzad