I just want to retrieve the data that save from sharedpreferences and display it in listview. Currently I just only manage to display the data with only one line in my SecondActivity. What I want is to display those data separately in listview, is there any expert how to solve this thanks in advance
My shared preferences
MainActivity to save sharedpref
public void save_append_list_tosharefpref (String data){
List<String> favorites = new ArrayList<String>();
SharedPreferences settings;
SharedPreferences.Editor editor;
settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor = settings.edit();
Map<String, ?> allPrefs = settings.getAll(); //my existing sharedPreference
Set<String> set = allPrefs.keySet();
if (allPrefs.toString() =="{}" || allPrefs.toString() =="[]"){
favorites.add(data);
}
else {
for(String s : set){
favorites.add(data);
favorites.add(allPrefs.get(s).toString());
Log.d(TAG,"bagona"+allPrefs.get(s).toString());
}
}
editor.putString(FAVORITES, favorites.toString());
editor.commit();
}
SecondActivity
public void view_from_shared_preferences(){
SharedPreferences settings;
SharedPreferences.Editor editor;
settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
editor = settings.edit();
Map<String, ?> allPrefs = settings.getAll(); //your sharedPreference
Set<String> set = allPrefs.keySet();
for(String s : set){
Log.d(TAG,"This is all data "+allPrefs.get(s).toString());
String rep =allPrefs.get(s).toString();
String seps = rep.replace("]", "");
String seps1 = seps.replace("[", "");
Log.d(TAG,"final data "+seps1);
arrayAdapter.add(seps1);
}
}