android preferences Fix preference summary not updated

This commit is contained in:
cip 2013-04-06 10:13:17 +02:00
parent 721a2c9d6c
commit c5f27719fe
3 changed files with 24 additions and 2 deletions

View File

@ -19,7 +19,6 @@
<string name="error_articleurlnotfound">Error: Loading article (Url: %1$s) failed.</string> <string name="error_articleurlnotfound">Error: Loading article (Url: %1$s) failed.</string>
<string name="pref_display_title">Display</string> <string name="pref_display_title">Display</string>
<string name="pref_zoom_title">Zoom</string> <string name="pref_zoom_title">Zoom</string>
<string name="pref_zoom_summary">%s</string>
<string name="pref_zoom_dialogtitle">Zoom</string> <string name="pref_zoom_dialogtitle">Zoom</string>
<string-array <string-array
name="pref_zoom_entries"> name="pref_zoom_entries">

View File

@ -7,7 +7,6 @@
<ListPreference <ListPreference
android:key="pref_zoom" android:key="pref_zoom"
android:title="@string/pref_zoom_title" android:title="@string/pref_zoom_title"
android:summary="@string/pref_zoom_summary"
android:dialogTitle="@string/pref_zoom_dialogtitle" android:dialogTitle="@string/pref_zoom_dialogtitle"
android:entries="@array/pref_zoom_entries" android:entries="@array/pref_zoom_entries"
android:entryValues="@array/pref_zoom_entryvalues" android:entryValues="@array/pref_zoom_entryvalues"

View File

@ -1,15 +1,39 @@
package org.kiwix.kiwixmobile; package org.kiwix.kiwixmobile;
import android.os.Bundle; import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
public class KiwixSettings extends PreferenceActivity { public class KiwixSettings extends PreferenceActivity {
ListPreference prefList;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
prefList = (ListPreference) findPreference("pref_zoom");
prefList.setDefaultValue(prefList.getEntryValues()[0]);
String ss = prefList.getValue();
if (ss == null) {
prefList.setValue((String)prefList.getEntryValues()[0]);
ss = prefList.getValue();
}
prefList.setSummary(prefList.getEntries()[prefList.findIndexOfValue(ss)]);
prefList.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
prefList.setSummary(prefList.getEntries()[prefList.findIndexOfValue(newValue.toString())]);
return true;
}
});
} }
} }