Disabling of Edittext in Android

Disabling of EditText in Android

I believe the correct would be to set android:editable="false".

And if you wonder why my link point to the attributes of TextView, you the answer is because EditText inherits from TextView:

EditText is a thin veneer over
TextView that configures itself to be
editable.

Update:
As mentioned in the comments below, editable is deprecated (since API level 3). You should instead be using inputType (with the value none).

How to disable EditText in Android

I think its a bug in android..It can be fixed by adding this patch :)

Check these links
question 1
and
question 2

Hope it will be useful.

EditText: how to enable/disable input?

I finally found a solution. It's a matter of calling

  • setFocusableInTouchMode(boolean)
  • setFocusable(boolean)

when the EditText is first created, so it can intercept the clicks. Then one can set those flags back again to make the EditText editable, request the focus, and manually show/hide the soft keyboard with InputMethodManager methods

How to make an EditText uneditable/disabled

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>

Enable/Disable editText with a Switch in Android Studio

You can set the OnCheckedChangeListener of the switch.

switchGaranzia.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//enable
} else {
//disable
}
}
});


Related Topics



Leave a reply



Submit