Hi Pascal,
meine Launcher Activity erbt von PreferenceActivity und ist die beim SDK mitgelieferte Beispiel PreferenceActivity, aber etwas angepasst.
die pref_general.xml mit 2 ListPreferences
<PreferenceScreen xmlns:android="ich darf keine links posten">
<CheckBoxPreference
android:key="checkbox_barrierfree"
android:title="@string/pref_title_barrier_free"
android:summary="@string/pref_description_barrier_free"
android:defaultValue="true" />
<!-- NOTE: Hide buttons to simplify the UI. Users can touch outside the dialog to
dismiss it. -->
<!-- NOTE: ListPreference's summary should be set to its value by the activity code. -->
<ListPreference
android:key="list_start"
android:title="@string/pref_title_start"
android:defaultValue="-1"
android:entries="@array/pref_start_titles"
android:entryValues="@array/pref_start_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null" />
<ListPreference
android:key="list_destination"
android:title="@string/pref_title_destination"
android:defaultValue="-1"
android:entries="@array/pref_destination_titles"
android:entryValues="@array/pref_destination_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null" />
<Preference
android:key="prefbutton_startNavigation"
android:title="Start Navigation" />
Die Launcher Acitivity hat die 2 globalen Variablen
L
istPreference listDestination;
ListPreference listStart;`
und
private void setupSimplePreferencesScreen() {
if (!isSimplePreferences(this)) {
return;
}
addPreferencesFromResource(R.xml.pref_general);
// Bind the summaries of EditText/List/Dialog/Ringtone preferences to
// their values. When their values change, their summaries are updated
// to reflect the new value, per the Android Design guidelines.
bindPreferenceSummaryToValue(findPreference("list_destination"));
listDestination = (ListPreference) findPreference("list_destination");
bindPreferenceSummaryToValue(findPreference("list_start"));
listStart = (ListPreference) findPreference("list_start");
...
}
});
Die Liste wird in einer inner AsynkTask Klasse gefüllt, da die Werte per WebService übers Netzwerk geschickt werden
listDestination.setEntries(locations);
listStart.setEntries(locations);
listDestination.setEntryValues(Ids);
listStart.setEntryValues(Ids);
Also erstmal alles ohne irgendwelche Modifikationen an der ListPreference bzw. dem Dialog. Es werden auch nur Strings als Entrys gespeichert und int als EntryValues.