views:

48

answers:

2

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.

+1  A: 

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

Scoobler
Note: When enabling it in code use setFocusableInTouchMode(true) as setFocusable(true) doesn't reanable it as you would expect - see comment 7 on the link.
Scoobler
Thanks. Marked this as the correct answer. Also +1.
MyNameIsZero
+1  A: 

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. ;-)

mreichelt
+1 for information regarding "focusable".
MyNameIsZero