Android 首选项 - 更改它们出现的顺序
我正在尝试创建以 PreferenceActivity
开头的类层次结构。
这个想法是基类包含“关于我”按钮,然后下一个类实现游戏/应用程序/壁纸的通用首选项,然后下一个类添加每个实际游戏/应用程序的细节。
这个想法很有效,但是因为我在每个级别从 XML 中“添加”首选项,所以它们首先显示最通用(最低级别)的首选项(例如我的“关于”按钮)。
理想情况下,我希望它们是相反的方式 - 以便特定的首选项出现在列表的顶部,通用的首选项出现在底部 - 有什么方法可以实现这一点(我已经阅读了 PreferenceFragments 和新的 PreferenceHeaders 甚至似乎没有提供任何东西?)
是否有任何编程方式可以在整体顺序内移动 PreferenceCategorys 或 PreferenceScreens ?
基本上当我使用时
addPreferencesFromResource(R.xml.clock_settings);
我想要一个
addPreferencesFromResourceAtBottom(R.xml.clock_settings);
I'm trying to create a hierarchy of classes which start with a PreferenceActivity
.
The idea is the base class contains the 'About Me' button, then the next class implements the generic preferences for games/apps/wallpapers and then the next class adds the the specifics for each actual Game/App.
The idea works well BUT because I'm 'adding' preferences from XML at each level, they appear with the most generic (lowest level) ones first (e.g. my 'About' button).
Ideally I'd like them to be the other way up - so that specific preferences appear at the top of the list and generic ones at the bottom - is there any way of achieving this (I've read through the docs on PreferenceFragments and the new PreferenceHeaders and even that doesn't seem to offer anything?)
Is there any programmatic way to move PreferenceCategorys or PreferenceScreens around within the overall order??
Essentially when I'm using
addPreferencesFromResource(R.xml.clock_settings);
I'd like to have a
addPreferencesFromResourceAtBottom(R.xml.clock_settings);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里很擅长回答自己的问题:)
解决方案位于
android:order
XML 参数 - 将其与Preference
(或PreferenceGroup
或其子类)一起使用将在屏幕上按正确的顺序排列内容!您还可以使用
setOrder() 动态更改此设置
但如果Preference
已添加到PreferenceGroup
中,则不会对其重新排序。I'm getting good at answering my own questions here :)
The solution lies in the
android:order
XML parameter - using that withPreference
(orPreferenceGroup
or a sub-class of it) will sort stuff into the right sequence on screen!You could also change this dynamically with
setOrder()
but it won't reorder thePreference
s if they've already been added to aPreferenceGroup
.