I have a database in my android app which contain 2 fields named "word" and "meaning".From this database, i can retrieve data(word,meaning) and then i have to save them to shared preference and these saved shared preferences will be showed in a listview. These are my goals.
Now,only I can retrieve data from the database and can show them into a list view.For this my codes were:
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);
}
String[] from = { "key_word","key_meaning" };
int[] to = { R.id.txt1,R.id.txt2};
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), list_of_wordmeanings, R.layout.list_layout, from, to);
listView.setAdapter(adapter);
I also can save data into shared preference like this:
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value);
editor.commit();
But i dont understand how to save these two fields(word,meaning) into a list of shared preference and show them(the shared preference list) into a listview. Can anyone help me how to do this???