Getting Shared Preferences And Displaying Them In A Listview
So I have some shared preferences in my main activity: SharedPreferences prefs = this.getSharedPreferences('myFavs', Context.MODE_PRIVATE); SharedPreferences.Editor editor = prefs.
Solution 1:
if I understood in correct sense, what you need is to retrieve all preference values.
for that you can use this ;
Map<String,?> allPrefs = prefs.getAll();
for(Map.Entry<String,?> entry : allPrefs.entrySet()){
String key = entry.getKey();
String value = entry.getValue().toString();
}
you can store the values to an array and use.
UPDATE
more precisely
publicString[] fetchAllPreference(){
String[] values = newString();
int index = 0;
Map<String,?> allPrefs = prefs.getAll();
for(Map.Entry<String,?> entry : allPrefs.entrySet()){
value[index++] = entry.getValue().toString();
}
return values;
}
you can use this function for getting all the preference and the returned String array you can provide to your Listview adapter
Post a Comment for "Getting Shared Preferences And Displaying Them In A Listview"