user2056245
user2056245

Reputation: 595

listview with the names of shared preferences and link them

i am developing an android-application in which i have one activity that creates Shared Preferences.

in the other activity i just want to retrieve the names of the shared preferences created by the first activity and populate those names in a list view. and i also want to link those names(in the listview) with the actual shared preferences.

Upvotes: 1

Views: 148

Answers (1)

Aaron He
Aaron He

Reputation: 5549

In the other activity, use SharedPreferences.getAll to get all values from shared preferences:

Map<String,?> values = prefs.getAll();

Then, you can iterate through values to get strings you want. Probably you can store those strings to an array. Next, initialize an ArrayAdapter to let the listview populate those data. Similar code is here:

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.list_item, strings);

    listView.setAdapter(adapter);

Upvotes: 2

Related Questions