java - save imageButton Visibility [Android] -


i making application android , have difficulties save visibility of imagebutton when clicked. search on other topics have not found solutions.

for example, have button become white when clicked, , want save visibility when switch activities or views :

onclicklistener oclfavourite = new onclicklistener() {     @override     public void onclick(view arg0) {         imagebutton favwhite = (imagebutton) findviewbyid(r.id.favoriwhite);         imagebutton favori = (imagebutton) findviewbyid(r.id.favorigrey);         favwhite.setvisibility(view.visible); //the white button want save         favourite.setvisibility(view.invisible); //the initial button     } }; favori.setonclicklistener(oclfavori); 

i tried study sharedpreferences function, succeed save textview don't know how proceed imagebutton or imageview.

you can toggle boolean flag whenever toggle between visibility , invisibility. , save flag in sharedpreferences. this

private boolean flag = true;  private void setvisible(){     flag = true;     yourview.setvisibility(view.visible);      // save flag }  private void setinvisible(){     flag = false;     yourview.setvisibility(view.invisible);      // save flag } 

now in oncreate

oncreate(bundle b){     .............     if(flag)        // make visible     else        // make invisible } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -