I have a PreferenceActivity building screen hierarchy from code, and I
need to force display hierarchy change dynamically when one of
SharedPreference value changed. I know this might be a kind of easy
quesiton, but I couldn't find answer anywhere in documentations or
discussion.
My PreferenceActivity is forming like this.
-----
public class MyPreferenceActivity extends PreferenceActivity
...
setPreferenceScreen(createPreferenceHierarchy());
}
private PreferenceScreen createPreferenceHierarchy()
{
// Root
PreferenceScreen root = getPreferenceManager
().createPreferenceScreen(this);
// Orientation tracking smoothing method preference
PreferenceScreen orientationsmoothingPref = getPreferenceManager
().createPreferenceScreen(this);
orientationsmoothingPref.setKey( (String) getResources().getText
(R.string.key_screen_orientation_smoothing_method) );
orientationsmoothingPref.setTitle
(R.string.title_screen_orientation_smoothing_method);
orientationsmoothingPref.setSummary
(R.string.summary_screen_orientation_smoothing_method);
root.addPreference(orientationsmoothingPref);
// List preference
ListPreference orientationsmoothinglistPref = new ListPreference
(this);
orientationsmoothinglistPref.setEntries
(R.array.entries_orientation_smoothing_method_preference);
orientationsmoothinglistPref.setEntryValues
(R.array.entryvalues_orientation_smoothing_method_preference);
orientationsmoothinglistPref.setKey( (String) getResources().getText
(R.string.key_preference_orientation_smoothing_method) );
orientationsmoothinglistPref.setTitle
(R.string.title_preference_orientation_smoothing_method);
orientationsmoothinglistPref.setSummary
(R.string.summary_preference_orientation_smoothing_method);
orientationsmoothinglistPref.setDefaultValue("No");
orientationsmoothingPref.addPreference(orientationsmoothinglistPref);
// Orientation smoothing parameters category
PreferenceCategory orientationsmoothingparameterPrefCat = new
PreferenceCategory(this);
orientationsmoothingparameterPrefCat.setTitle
(R.string.title_category_orientation_smoothing_method_parameter);
orientationsmoothingPref.addPreference
(orientationsmoothingparameterPrefCat);
String orientationsmoothingmethodStr =
orientationsmoothinglistPref.getValue();
if ( orientationsmoothingmethodStr.compareTo("no") == 0 )
{
/* In case orientation smoothing method is "No" */
// Nothing to do.
}
else if ( orientationsmoothingmethodStr.compareTo("ma") == 0 )
{
/* In case orientation smoothing method is "Moving Averaging" */
// Edit text preference
EditTextPreference maNPref = new EditTextPreference(this);
maNPref.setKey( (String) getResources().getText
(R.string.key_preference_ma_n) );
maNPref.setDialogTitle(R.string.title_preference_ma_n);
maNPref.setTitle(R.string.title_preference_ma_n);
maNPref.setSummary(R.string.summary_preference_ma_n);
maNPref.setDefaultValue("10");
orientationsmoothingparameterPrefCat.addPreference(maNPref);
}
else if ( orientationsmoothingmethodStr.compareTo("ses") == 0 )
{
/* In case orientation smoothing method is "Single Exponential
Smoothing" */
// Edit text preference
EditTextPreference sesalphaPref = new EditTextPreference(this);
sesalphaPref.setKey( (String) getResources().getText
(R.string.key_preference_ses_alpha) );
sesalphaPref.setTitle(R.string.title_preference_ses_alpha);
sesalphaPref.setDialogTitle(R.string.title_preference_ses_alpha);
sesalphaPref.setSummary(R.string.summary_preference_ses_alpha);
sesalphaPref.setDefaultValue("0.3");
orientationsmoothingparameterPrefCat.addPreference(sesalphaPref);
}
else if ( orientationsmoothingmethodStr.compareTo("des") == 0 )
{
/* In case orientation smoothing method is "Single Exponential
Smoothing" */
// Edit text preference
EditTextPreference desalphaPref = new EditTextPreference(this);
desalphaPref.setKey( (String) getResources().getText
(R.string.key_preference_des_alpha) );
desalphaPref.setTitle(R.string.title_preference_des_alpha);
desalphaPref.setDialogTitle(R.string.title_preference_des_alpha);
desalphaPref.setSummary(R.string.summary_preference_des_alpha);
desalphaPref.setDefaultValue("0.3");
orientationsmoothingparameterPrefCat.addPreference(desalphaPref);
// Edit text preference
EditTextPreference desgammaPref = new EditTextPreference(this);
desgammaPref.setKey( (String) getResources().getText
(R.string.key_preference_des_gamma) );
desgammaPref.setTitle(R.string.title_preference_des_gamma);
desgammaPref.setDialogTitle(R.string.title_preference_des_gamma);
desgammaPref.setSummary(R.string.summary_preference_des_gamma);
desgammaPref.setDefaultValue("1.0");
orientationsmoothingparameterPrefCat.addPreference(desgammaPref);
}
return root;
}
-----
What I want to do it is everytime ListPreference's value changes,
force redisplay PreferenceScreen. If anyone have any hint, please
reply here. Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---