Android的preferences - 改变它们出现的顺序顺序、Android、preferences

2023-09-06 18:11:39 作者:心酸已久

我试图创建类层次结构,其与preferenceActivity启动。

I'm trying to create a hierarchy of classes which start with a PreferenceActivity.

我们的想法是基类包含了关于我按钮​​,然后下一个类实现了游戏/应用/墙纸通用preferences再下一类为每个实际的游戏/应用程序的细节。

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.

这个想法运作良好,而是因为我是从XML在每个级别'添加'preferences,他们似乎最通用的(最​​低级别)的人第一(例如我的关于按钮)。

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

在理想情况下,我想他们是其他方式了 - 这样的特定preferences出现在列表和通用那些在底部的顶部 - 是否有实现这一目标的任何方式(我读过通过在preferenceFragments和新的preferenceHeaders甚至认为似乎没有的文档提供什么吗?)

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??

本质上讲,当我使用

添加preferencesFromResource(R.xml.clock_settings);

addPreferencesFromResource(R.xml.clock_settings);

我想有一个

添加preferencesFromResourceAtBottom(R.xml.clock_settings);

addPreferencesFromResourceAtBottom(R.xml.clock_settings);

推荐答案

我越来越善于在这里回答我自己的问题:)

I'm getting good at answering my own questions here :)

解决方案在于 安卓游戏排序 XML参数 - 使用与 preference (或 preferenceGroup 或子类的话)将整理成的东西在屏幕上正确的顺序!

The solution lies in the android:order XML parameter - using that with Preference (or PreferenceGroup or a sub-class of it) will sort stuff into the right sequence on screen!

您也可以改变这一点与动态的 setOrder() 但不会重新排序 preference ■如果他们'已经已经被添加到 preferenceGroup

You could also change this dynamically with setOrder() but it won't reorder the Preferences if they've already been added to a PreferenceGroup.