android - If one button press does something, other buttons pressed should do something else -


i have 5 buttons in activity. code should work follows : 1 (correct) button pressed should something. other 4 pressed, else should done... don't want used 5 onclicklistener

if(button1 press) {     }  else if (button2 or button3 or button4 or button5 press) {     else } 

why don't way:

final button button1 = (button) findviewbyid(r.id.button1); final button button2 = (button) findviewbyid(r.id.button2); final button button3 = (button) findviewbyid(r.id.button3); final button button4 = (button) findviewbyid(r.id.button4); final button button5 = (button) findviewbyid(r.id.button5);  onclicklistener listener = new onclicklistener() {     @override     public void onclick(view v) {         if (v.equals(button1)) {             //         } else {             // else         }     } };  button1.setonclicklistener(listener); button2.setonclicklistener(listener); button3.setonclicklistener(listener); button4.setonclicklistener(listener); button5.setonclicklistener(listener); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -