android - Button Background Image change on click -


i have button begins life "unticked" text going label says "no". when push button changes image "ticked" , displays text in label "yes". works perfectly. can't or find how change "unticked" , "no" if push again?

here code button:

view.onclicklistener imgbuttonhandler9 = new view.onclicklistener() {          public void onclick(view v) {             button9.setbackgroundresource(r.drawable.androidnearmisson);               textview text = (textview) findviewbyid(r.id.textview2);             text.settext("yes");          }     }; 

any appreciated.

many thanks

you can textview's current text , make comparison. if yes, change no, else vice verse:

view.onclicklistener imgbuttonhandler9 = new view.onclicklistener() {      public void onclick(view v) {         textview text = (textview) findviewbyid(r.id.textview2);         if(text.gettext().tostring().equals("no")){             button9.setbackgroundresource(r.drawable.androidnearmisson);             text.settext("yes");         }         else {             button9.setbackgroundresource(r.drawable.otherimage);  //replace otherimage proper drawable id             text.settext("no");         }     } }; 

hope helps.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -