android - hiding imagebutton1 on click then show imagebutton2 -


i have 2 image buttons. imagebutton & imagebutton2 , have place them both 1 on top , setted imagebutton2 ( invisible ).

my goal click imagebutton1 hide imagebutton1 , show imagebutton2.

here code have

btn2.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view v) {                          p.setflashmode(camera.parameters.flash_mode_off);                          camera.setparameters(p);                        camera.stoppreview();                         islighon = false;                     findviewbyid(r.id.imagebutton).setbackgroundresource(r.drawable.offf);                     //    imagebutton2.setvisibility(view.invisible);                  }             });                btn1.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     p.setflashmode(camera.parameters.flash_mode_torch);                     camera.setparameters(p);                     camera.startpreview();                     islighon = true;                     // imagebutton2.setvisibility(view.visible);                     // findviewbyid(r.id.imagebutton).setbackgroundresource(r.drawable.onn);                     // imagebutton btn1 = (imagebutton) findviewbyid(r.id.imagebutton);                     //  btn1.setimageresource(r.drawable.onn);                      //findviewbyid(r.id.imagebutton).setbackgroundresource(r.drawable.onn);                   }              }); 

these code below

imagebutton2.setvisibility(view.visible); imagebutton2.setvisibility(view.invisible); 

crashes app when click it

your imageviews null when accessing them. need initialize them before using:

imagebutton1 = (imagebutton) findviewbyid(r.id.imagebutton1); imagebutton2 = (imagebutton) findviewbyid(r.id.imagebutton2); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -