0

I have a contact name in my widget configuration class and i save it with the following code:

String name= mAppWidgetPrefix.getText().toString();
save(context, mAppWidgetId, name);

static void save(Context context, int appWidgetId, String text) {
SharedPreferences.Editor prefs = context.getSharedPreferences(
PREFS_NAME, 0).edit();
prefs.putString(PREF_PREFIX_KEY + appWidgetId, text);
prefs.commit();
}

I load it with this:

static String load(Context context, int appWidgetId) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
String prefix = prefs.getString(PREF_PREFIX_KEY + appWidgetId, null);

return prefix;

}

It works fine, but i want to save the phone number too. How do I need to change the code?

String numberPrefix = pickedNumber.getText().toString(); //I need to save this too
keybee
  • 1,498
  • 20
  • 32

1 Answers1

2

Just specify another key for saving. Like this:

SharedPreferences.Editor prefs = context.getSharedPreferences(
PREFS_NAME, 0).edit();
prefs.putString(PREF_PREFIX_KEY_NUMBER + appWidgetId, text);
prefs.commit();
olshevski
  • 4,971
  • 2
  • 35
  • 34
  • your answer was helpful. I have another problem, but I don't find a solution. Please check it if you have time: http://stackoverflow.com/questions/13025290/displaying-contacts-photo-by-photo-id – keybee Oct 28 '12 at 13:04