开发者

Problem temporarily disabling a EditText field

I'm trying to create an activity which gets input in the开发者_C百科 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜