我有三个按钮
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;
}
当它到达开关时它会断开,任何人都可以帮助我吗?第一篇文章希望每个人都好吗
答案 0 :(得分:5)
在
中更改它 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;
}
答案 1 :(得分:5)
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;
}