I have three buttons
Button1 btn1 = (Button) findViewById(R.id.button1);
Button2 btn2 = (Button) findViewById(R.id.button2);
Button3 btn3 = (Button) findViewById(R.id.button3);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
public void onClick(View v) {
switch(v){
case bt1:
//SOME CODE
break;
case bt2:
//SOME CODE
break;
case bt3:
//SOME CODE
break;
}
It breaks when it gets to the switch, can anyone help me? first post hope everythings ok
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
//SOME CODE
break;
case R.id.button2:
//SOME CODE
break;
case R.id.button3:
//SOME CODE
break;
}
change it in
Button1 btn1 = (Button) findViewById(R.id.button1);
Button2 btn2 = (Button) findViewById(R.id.button2);
Button3 btn3 = (Button) findViewById(R.id.button3);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
btn3.setOnClickListener(this);
public void onClick(View v) {
switch(v.getId()){
case R.id.button1:
//SOME CODE
break;
case R.id.button2:
//SOME CODE
break;
case R.id.button3:
//SOME CODE
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With