Android Preferences - changing the order in which they appear

百般思念 提交于 2019-12-08 02:47:53

问题


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

回答1:


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

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!

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



来源:https://stackoverflow.com/questions/7676998/android-preferences-changing-the-order-in-which-they-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!