I have wrote a little code to save new just added items to sharedpreferences. But if I retrieve the sharedpreferences in an arraylist it displays {"todo":"new item" } but I only want to display one item and only the text if you understand me. Here is my save Arraylist code:
public void saveArrayList(Context context ,ArrayList<DayItems> mlist){
SharedPreferences shared;
SharedPreferences.Editor editor;
shared = context.getSharedPreferences("MONDAY", Context.MODE_PRIVATE);
editor = shared.edit();
Gson gson = new Gson();
String json = gson.toJson(mlist);
editor.putString("mondAy", json);
String getSaved = shared.getString("mondAy", null);
Toast.makeText(PlannerActivity.this, getSaved, Toast.LENGTH_LONG).show();
editor.commit();
}
Here is my add item to arraylist:
@Override
public void onClick(View v) {
String afspraak = addTEXT.getText().toString().trim();
if(afspraak.length()>0){
addTEXT.setText("");
mon.add(new DayItems(afspraak));
dayAdapter.notifyDataSetChanged();
//save arraylist with new item
saveArrayList(context, mon);
}
}
});
Actually what I want is a snippet to retrieve SharedPreferences.
Thanks in Advance!