Vote count:
0
I'm using a preference screen in a non-standard way, to set values for a class called Reminder. When I open the EditReminder activity with an existing reminder, it pulls in the appropriate reminder from an intent, and then initializes the preference screen like so:
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("temp_name",reminder.getName());
Toast.makeText(getActivity(), reminder.getName(), Toast.LENGTH_LONG).show();
editor.putString("temp_description",reminder.getDescription());
editor.putString("temp_time",timeFormat.format(reminder.getDate().getTime()));
editor.putString("temp_date",dateFormat.format(reminder.getDate().getTime()));
editor.apply();
name.setSummary(reminder.getName());
description.setSummary(reminder.getDescription());
time.setSummary(timeFormat.format(reminder.getDate().getTime()));
date.setSummary(dateFormat.format(reminder.getDate().getTime()));
When I first open the app and attempt to edit an existing reminder, this works flawlessly. However, from then on, the summaries will be correctly set to the correct values, and if I save immediately the correct values get saved, so the code appears to be working. Except that if I tap a preference, the pre-filled value is for the previous reminder.
So if I open Reminder1 and tap name, it prefills the edittext dialog with "Reminder1"
Then if I open Reminder2 and tap name, it prefills the edittext dialog with "Reminder1"
Then if I open Reminder3 and tap name, it prefills the edittext dialog with "Reminder2"
The toast is there for value testing, since my logcat lags by about 8 minutes, but that's another question. The toast displays the correct value. Also, as I mentioned, the summaries are set to the correct value, and if I save without making any changes, it saves the correct values. I'm baffled.
Android Preference value behaving strangely
Aucun commentaire:
Enregistrer un commentaire