是否有可能定义在preferenceActivity一个RadioGroup中? 我可以提供多选择的时候只能找在ListView。
Is it possible to define a RadioGroup in a PreferenceActivity? I could only find the ListView when offering multiple-choices.
我缺少的东西?
欢迎您延长的任意的 preference
类。我没有你正在寻找什么延长 preferenceCategory
为例。添加子preferences(如 preferenceScreen
和的EditText preference
)像通常与添加preference()
,其覆盖和变更/设定部件由code与 setWidgetLayoutResource()资源
。当然,新的部件应该包含一个单选
。设置自定义在preferenceClickListener
与西顿preferenceClickListener()
。
You are welcome to extend any Preference
class. I did exactly what you are looking for by extending PreferenceCategory
for example. Add child preferences (such as PreferenceScreen
and EditTextPreference
) like normally with addPreference()
, override it and change/ set the widget resource by code with setWidgetLayoutResource()
. Naturally, your new widget should contain a RadioButton
. Set a custom OnPreferenceClickListener
with setOnPreferenceClickListener()
.
接下来取得 onCreateView一个参考
。然后你可以将它转换为的ViewGroup
父母()的ListView
在 onBindView()
,并设定 OnHierarchyChangeListener
就可以了。现在,你得到通知时,孩子 preference
的查看
s的加入的ListView
。设置一个新的 View.OnClickListener
在新的查看
层次结构中,但只有当查看
包含单选
。现在管理的点击次数。
Next get a reference to the ViewGroup
"parent" in onCreateView()
. Then you can cast it to ListView
in onBindView()
, and set a OnHierarchyChangeListener
on it. Now you get notified when the child Preference
's View
s are added to the ListView
. Set a new View.OnClickListener
on the new View
in the hierarchy, but only if the View
contains a RadioButton
. Now manage the clicks.
它实际上是pretty的容易,如果你只需要添加 preferenceScreen
儿童。我还需要将其与的EditText preference
,这是棘手的部分。
It's actually pretty easy if you only need to add PreferenceScreen
as children. I also needed it with a EditTextPreference
, which was the tricky part.
的好处很简单:你会得到默认的preference框架的外观和行为的目录preference范围之外
。 A 目录preference
看起来也不同。此外,目录preference
只能包含pre定义的值。所以,如果你需要一个的EditText preference
来用一个单选按钮选择,这将是不可能的。
The benefits are simple: you get the default preference framework look and behaviour outside the context of a ListPreference
. A ListPreference
also looks different. Also, a ListPreference
can only contain pre-defined values. So if you need a EditTextPreference
to be selected with a radio button, that wouldn't be possible.