In a tabbed view, I have two activities where I want to display the
same preference. One tab is a preference activity and the other is an
ordinary activity. Although this seems straightforward, the screens
are not staying in sync.
When I modify the checkbox in the ordinary activity tab, I fetch the
shared preference with the Checkbox Preference key and edit the value
as needed, committing the change to Shared Preferences (code pasted
below). The PreferencesActivity should display the shared preference
value and does not seem to get the update.
The reverse is also true. If I set the preference in the preferences
activity, my regular activity should read the update and display the
checkbox to match the preference screen. Maybe a view of the activity
is cached. Does that explain both cases? How do I ask the system to
redraw the tab rather than use a cached view?
Here are snippets, for clarity in my description:
>From the ordinary activity -
if(mPreferences.getBoolean(getString(R.string.sch_enabled), false)) {
enabled.setChecked(true);
other stuff to do
} //no else clause included
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
if (isChecked) {
//code to handle enabling through the scheduler
checkbox
mEditor.putBoolean(getString(R.string.sch_enabled), true);
mEditor.commit();
} else {
mEditor.putBoolean(getString(R.string.sch_enabled), false);
mEditor.commit();
}
} //other code not included
>From preferences.xml:
<CheckBoxPreference android:key="@string/sch_enabled"
android:title="@string/enable_cb"
android:summary="@string/sched_desc"
android:defaultValue="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
If anybody has dealt with this, I sure would appreciate a tip.
Best regards,
Beth
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---