Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

refreshing views of Preferences when using PreferenceActivity

Tags:

java

android

I'm trying to force PreferenceActivity to refresh. Does anyone know how to do this?

I have a ResetDefaultsPreference class that subclasses Preference and, when clicked, is supposed to reset to defaults all preferences whose keys start with a certain prefix. It works, but when I hit the reset preference, none of the preferences in that screen update until I back out of the screen and go back in. (That works for some custom color preferences, but even that doesn't work for some ListPreferences - for those I have to leave and re-enter the PreferenceActivity itself for the updated values to be shown.)

I tried to fix this by getting the root view and invalidate()ing it, but that doesn't seem to work. Here's the line to refresh the display. It's in part of a Preference subclass that keeps the Context it was created with in mContext.

((Activity)mContext).findViewById(android.R.id.content).invalidate();

This happens after the preference values have been changed and committed. (The values change, but the display doesn't.) Does anyone know how I can force PreferenceActivity to refresh itself?

like image 816
tmandry Avatar asked Jun 17 '11 02:06

tmandry


1 Answers

I don't know of a way to "refresh" the PreferenceActivity, but you can create the illusion to the user. It will will close and reopen the activity with no animations, so it will appear as if the value just changes.

Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
like image 145
stipe108 Avatar answered Oct 07 '22 09:10

stipe108