Show the actual current setting of the preference in the summary.master
parent
385a3509a8
commit
f4e3d097fe
@ -1,15 +1,33 @@ |
|||||||
package com.levien.synthesizer.android.ui; |
package com.levien.synthesizer.android.ui; |
||||||
|
|
||||||
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; |
||||||
|
|
||||||
import com.levien.synthesizer.R; |
import com.levien.synthesizer.R; |
||||||
|
|
||||||
public class SettingsActivity extends PreferenceActivity { |
public class SettingsActivity extends PreferenceActivity { |
||||||
|
@SuppressWarnings("deprecation") |
||||||
@Override |
@Override |
||||||
public void onCreate(Bundle savedInstanceState) { |
public void onCreate(Bundle savedInstanceState) { |
||||||
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
||||||
addPreferencesFromResource(R.xml.preferences); |
addPreferencesFromResource(R.xml.preferences); |
||||||
|
ListPreference keyboardTypePref = (ListPreference)findPreference("keyboard_type"); |
||||||
|
updateListSummary(keyboardTypePref, keyboardTypePref.getValue()); |
||||||
|
keyboardTypePref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { |
||||||
|
public boolean onPreferenceChange(Preference pref, Object newVal) { |
||||||
|
updateListSummary(pref, newVal.toString()); |
||||||
|
return true; |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
private void updateListSummary(Preference pref, String newVal) { |
||||||
|
ListPreference lp = (ListPreference)pref; |
||||||
|
int index = lp.findIndexOfValue(newVal); |
||||||
|
lp.setSummary(lp.getEntries()[index]); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
Loading…
Reference in new issue