How To Save Dynamically Added Items In Listview With Sharedpreferences?
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_mai
Solution 1:
You can save to shared preference in this way
SharedPreferencessp= context.getSharedPreferences(
"file name", 0);
SharedPreferences.EditorspEdit= sp.edit();
spEdit.putLong(key, value);
spEdit.commit();
Solution 2:
You are supposed to store single key-value paired data with SharedPreferences. Trying to store big grouped data is not efficient at all. You should use an SQLite database.
SQLite and ContentProvider Tutorial
Solution 3:
You can store string sets in Shared Preferences, then convert them back to a List when you retrieve them.
ArrayList<String> list = newArrayList<String>();
list.add("test1");
list.add("test2");
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putStringSet("stringset", newHashSet<String>(list))
.commit();
Post a Comment for "How To Save Dynamically Added Items In Listview With Sharedpreferences?"