Alright so, I am trying to save a set of three phone numbers to a shared pref. When I hit save it goes through all the code and the toast and the end pops up but the numbers that should have been saved do not show instead it showed the default text I input for each number. Interested conundrum. Anyway here in the code chunk I am working with.
saveNums.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String num1String;
num1String = num1.getText().toString();
SharedPreferences.Editor editor = prefs.edit();
editor.putString(constants.num1, num1String);
editor.commit();
String num2String;
num2String = num2.getText().toString();
SharedPreferences.Editor editor2 = prefs.edit();
editor2.putString(constants.num2, num2String);
editor2.commit();
String num3String;
num3String = num3.getText().toString();
SharedPreferences.Editor editor3 = prefs.edit();
editor3.putString(constants.num3, num3String);
editor3.commit();
Toast.makeText(c, "Contact's have been saved: " + "\n" + constants.num1 + "\n" + constants.num2 + "\n" + constants.num3, Toast.LENGTH_LONG)
.show();
}
});
And here is the shared pref file:
import android.content.SharedPreferences;
public class constants {
public static String PREF_NAME = "sharedString";
public static String num1 = "num1";
public static String num2 = "num2";
public static String num3 = "num3";
SharedPreferences prefs;
}
No errors are coming up when I hit that saveNums button. All the same the numbers are not being saved either. Any ideas on how to fix this would be awesome.