正确RadioGroup中以preferenceActivity中以、正确、RadioGroup、preferenceActivity

2023-09-07 16:37:47 作者:每晚半夜偷菜,累不累。

是否有可能定义在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 Views 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.

 
精彩推荐
图片推荐