简体   繁体   中英

Adding headers to a PreferenceActivity

So I have a PreferenceActivity subclass in my Honeycomb app and there should be functionality for adding accounts for a certain service. I use loadHeadersFromResource to load preference headers from the xml, but I also want accounts to be added to the header list, just like in GMail app. Is there any way to do it without writing my own PreferenceActivity ?

Thanks

This is not specific to honeycomb it works on Android 2.1 etc. as well. Just use PreferenceCategory as your headers and add the preference to the category.

Something like this in the onCreate.

PreferenceScreen pf = getPreferenceManager().createPreferenceScreen(this);
pf.setPersistent(true);
setPreferenceScreen(pf);

PreferenceCategory account1 = new PreferenceCategory(this);
account1 .setTitle("Account 1");
pf.addPreference(account1 );


Preference p = ...;
account1.addPreference(p);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM