read

NOTE: when you set the default value you must set a CharSequence object, not a String, I don’t know why but when you use String, even with the same object, it dosen’t work.

Note to create a category and a listpreferences

The class must extend PreferenceActivity and onCreate:

<pre style="background-image: URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"> PreferenceCategory mainCategory = new PreferenceCategory(this);
// Root
PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
mainCategory.setTitle("Category Title");
root.addPreference(mainCategory); // Adding a category
CharSequence[] entries = {"Two", "One", "Other"};
// PREFERENCE device
final ListPreference listPref = new ListPreference(this);
listPref.setKey("keyDevice"); // Refer to get the pref value
listPref.setDefaultValue("One");
listPref.setEntries(entries);
listPref.setEntryValues(entries);
listPref.setDialogTitle("Title");
listPref.setTitle("Title 2");
listPref.setSummary("Summary");
mainCategory.addPreference(listPref); // Adding under the category
listPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
//newValue will be the entryValue for the entry selected
return true;
}
});
this.setPreferenceScreen(root);
</pre><div class="p1">
Source</div>

Blog Logo

Daniel Gomez Rico


Published

Image

MakinGIANTS

The findings and tips records of an Android-iOS-TheWholeShabang group

Back to Overview