我从数据库中检索 5 条数据(其中有 2 列单词和含义)并将它们保存到共享首选项中。所以我有 5 个关于共享偏好的项目。现在我如何将它们显示到列表视图中。我尝试了很多次,但无法解决这个问题。我的代码是:
ArrayList<HashMap<String, String>> list_of_wordmeanings = new ArrayList<HashMap<String, String>>();
Cursor mCursor = mDbHelper.learn_getTestData();
for (int i = 0; i < mCursor.getCount(); i++)
{
mCursor.moveToPosition(i);
String string = mCursor.getString(1);
HashMap<String, String> hm = new HashMap<String, String>();
String word = mCursor.getString(0).toString();
String meaning = mCursor.getString(1).toString();
hm.put("key_word",word);
hm.put("key_meaning",meaning);
list_of_wordmeanings.add(hm);
}
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
for (HashMap<String, String> map : list_of_wordmeanings)
for (Entry<String, String> entry : map.entrySet())
{
editor.putString(entry.getKey(), entry.getValue());
editor.commit();
String savedPref = sharedPreferences.getString(entry.getKey(), "");
Toast.makeText(getApplicationContext(),savedPref, Toast.LENGTH_LONG).show();
}
它从 Toast 中烤出 5 个键和值。现在我必须将这些键和相应的值显示到列表视图中。我怎样才能做到这一点??