java - Android: Save view that was added in RecyclerView with SharedPrefs -


i'm adding views recyclerview clicking on button, want views saved, preferably in sharedprefrences how , need json?

here's adapter:

public class subjectsadapter extends recyclerview.adapter<subjectsadapter.viewholder> {      public list<string> items = new arraylist<>();     public activity mcontext;      public subjectsadapter(activity context) {         this.mcontext=context;     }      public void additem(string name) {         items.add(name);         notifyiteminserted(items.size() - 1);     }      public void removeitem(int position) {         items.remove(position);         notifyitemremoved(position);     }      @override     public viewholder oncreateviewholder(viewgroup parent, int viewtype) {         layoutinflater inflater = layoutinflater.from(parent.getcontext());         view view = inflater.inflate(r.layout.grid_item_button, parent, false);         view.requestfocus();         return new viewholder(view);     }      @override     public void onbindviewholder(viewholder holder, int position) {     }      @override     public int getitemcount() {         return items.size();     }      static int = 100;     static int h = 1000;     public edittext editname;      class viewholder extends recyclerview.viewholder{          public button gridbutton;         private textview classname;         public sharedpreferences prefs;          public viewholder(view itemview) {             super(itemview);              gridbutton = (button) itemview.findviewbyid(r.id.grid_button);             editname = (edittext) itemview.findviewbyid(r.id.editname);             classname = (textview) itemview.findviewbyid(r.id.classname);             prefs = mcontext.getpreferences(context.mode_private);              gridbutton.setid(++i);             gridbutton.settext(prefs.getstring("key", + ""));              editname.requestfocus();         }     } } 

i'm adding views activity adapter.additem("something");

you cant' store views in sharedpreference, can store value of textview.

pref = getsharedpreferences(prefname, context.mode_private); sharedpreferences.editor ed; ed = pref.edit(); ed.putstring(prefkey2, textview.gettext().tostring()).commit(); 

then can set stored value textview

textview.settext(pref.getstring(prefkey2, "")); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -