MyName
MyName

Reputation: 2236

Problem temporarily disabling a EditText field

I'm trying to create an activity which gets input in the following form:

() Option 1  (a RadioButton)
() Option 2  (a RadioButton)
() Custom    (a RadioButton)
[     ]      (a EditText)

The idea is that the user can either choose one of the two predefined values, or enter a custom value. In order for him to enter a custom value, he must activate the "() Custom" RadioButton.

<EditText 
  android:id="@+id/CustomValue"
  android:text="" 
  android:enabled="false"
  android:inputType="phone"
  android:digits="0123456789." />

The problem is the following

When this code is executed, before the "() Custom" RadioButton is checked, the EditText appears in a shaded color (unlike the ones which do not have enable=false). However, if the TextView is clicked, the input keyboard is displayed and it accepts input.

Does anyone know how to solve this? Thanks.

Upvotes: 1

Views: 1226

Answers (2)

mreichelt
mreichelt

Reputation: 12455

Maybe you should also set android:focusable to false so the text field is not selected automatically. But don't forget to set it to true again if you enable it. ;-)

Upvotes: 1

Scoobler
Scoobler

Reputation: 9719

I think at the moment this is an issue and has been reported to Android as a bug.

You can set the EditText as:

android:focusable="false"

This won't allow the user to select the field to type into it.

Alternatively you could set the field to:

android:visibility="gone"

or:

android:visibility="invisible"

Then change the visibility to visible.

See the following for more details:

http://code.google.com/p/android/issues/detail?id=2771

Upvotes: 1

Related Questions