java - Layout color change is not retained when App reopened -


alert dialog opens when textview clicked. if user selects value, layout color should change else not. working fine. when close , reopen tab, color not retained. how retain color after app reopened.

xml:

<linearlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="#ffffff"     android:orientation="horizontal"     android:id="@+id/linearlayout1"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"    >  <imageview     android:id="@+id/imageview1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@drawable/genere"/>  <textview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/genere"     android:layout_gravity="center"     android:text=" search genre"     android:textsize="20sp"/>  </linearlayout> 

onclick:

views mviews = new views(); mviews.genere.setonclicklistener(this);   public void onclick(view v) { switch (v.getid()){     case r.id.genere:          ilist();         break; 

java:

    public arraylist<string> ilist() {      final string[] ratings = new string[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};     final boolean[] ratingschecked = {false, false, false, false, false, false, false, false, false, false};     sharedpreferences sharedpreferences = this.getsharedpreferences("checkedrate_i", context.mode_private);     final sharedpreferences.editor editor = sharedpreferences.edit();      final alertdialog.builder builder = new alertdialog.builder(this);      builder.settitle("select ratings");     builder.setmultichoiceitems(ratings, ratingschecked, new dialoginterface.onmultichoiceclicklistener() {         @override         public void onclick(dialoginterface dialog, int which, boolean ischecked) {              if (ischecked) {                     if(!ilist.contains(ratings[which])){                        ilist.add(ratings[which]);                      }              } else if (ilist.remove(ratings[which])) {                  if(ilist.contains(ratings[which])){                     ilist.remove(ratings[which]);                 }               }         }     }).setpositivebutton("ok", new dialoginterface.onclicklistener() {         @override         public void onclick(dialoginterface dialog, int which) {                  (int = 0; < ilist.size(); i++) {                 editor.putstring("selectedratings" + i, string.valueof(ilist.get(i)));             }             editor.putint("size", ilist.size());              editor.apply();    > if(!(ilist.isempty)){ >               //change gray color >             } >            else{ >              //change white color. >               }          }     }).setnegativebutton("cancel", new dialoginterface.onclicklistener() {         @override         public void onclick(dialoginterface dialog, int which) {          }     });      alertdialog dialog = builder.create();     builder.show();     return ilist;     } 

how retain color change made in list method when app reopened.

save selected color in sharedpreferences , retrieve when creating dialog. or check size saved in sharedpreferences if greater 0 user selected value , color should change otherwise not.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -