listview - Android: Save State of color change even after the app is closed -


i want save state of color of text in listview when clicked on item. have custom adapter doing thing correct color remains changed when user in app. , user closes app. color once again set previous 1 .i.e default one. have tried save color state in arraylist using position of getview thats not working me. or should use db that? idea how save state of color after user closes app. , @ start of getview access state , set color accordingly. concept see in email apps. mails marked read , unread different colors , text styles. have explained problem , if want more explanation please tell me will.

this adapter code:

arraylist<readnotifications> savestate;  public adatperreadnotification(context context , arraylist<readnotifications> save) {         this.context = context;         this.savestate = save;     }    @override     public view getview(final int position, view view , viewgroup arg2) {          layoutinflater inflater = (layoutinflater)context.getsystemservice(context.layout_inflater_service);         if (view == null)         {             view = inflater.inflate(r.layout.adapter_readnotificaiton, null);         }          readnotifications details = savestate.get(position);          textview tv = (textview) view.findviewbyid(r.id.txtview);           if(savestate.get(position).isselected)         {                     // if clicked set color on start of view             tv.settextcolor(color.gray);         }          else{                             // set default color                 tv.settextcolor(color.rgb(0,255,255));         }          date.settext(details.tvtext());          tv.setonclicklistener(new view.onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                  tv.settextcolor(color.gray);                 intent intent = new intent(context,readnotif.class);                 v.getcontext().startactivity(intent);                 savestate.get(position).isselected = true;             }         });           return view;     } 

and readnotifications class:

public class readnotifications implements serializable {      public boolean isselected;     contentvalues colmnvalues;         public readnotifications(contentvalues values  )      {         colmnvalues = values;     }        public string tvtext() {         return getvalue(colmnvalues.get("tvtext"));     }       private string getvalue(object obj){         if(obj == null){             return "";         }         return (string) obj;     }   } 

just simple trick : -

use sharedpreferences in app.

you can save color hash values or string or object in sharedpreferences.

if need save states of items sharedpreferences better option you.

thanks


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -