0
私は、ある量のクリックの後に戻ることができる複数のボタンを作る方法が不思議です。 3番目の間違ったボタンを押すと元に戻りません。誰かがどこに間違っているのか教えてください。 第三の試みの後に、それはあなたがメソッドにturnsLeftグローバル変数を渡しているmutlipeボタンの選択android
private boolean answer = false;
private int turnsLeft = 0;
Button btn1;
Button btn2;
Button btn3;
Button btn4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cat);
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(this);
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(this);
btn3 = (Button) findViewById(R.id.btn3);
btn3.setOnClickListener(this);
btn4 = (Button) findViewById(R.id.btn4);
btn4.setOnClickListener(this);
}
public void onClick (View view){
switch (view.getId()){
case R.id.btn1: {
Intent intent = new Intent(Cat.this,Congratulations.class);
startActivity(intent);
break;
}
case R.id.btn2: {
animalButtonClicked(btn2,turnsLeft);
break;
}
case R.id.btn3: {
animalButtonClicked(btn3,turnsLeft);
break;
}
case R.id.btn4: {
animalButtonClicked(btn4,turnsLeft);
break;
}
default:{
break;
}
}
}
private int animalButtonClicked(Button button, int count){
button.setEnabled(false);
count++;
if(count == 3){
count = 0;
finish();
}
button.setEnabled(false);
return count;
}
となる場合はどうなるのですか? – Bharatesh
は、3回の試行後にアクティビティを変更する必要があります –