18 個のボタン (bAnswer1 から bAnswer18) と 6 つのテキストビュー (tvAnswer1 から 6) を持つアプリを作成しています。私の意味は、6 つの単語を 2 つの 3 つの単語 (ボタン、ボタン、ボタンなど) にスライスすることです。6 つの単語でそれを行い、それぞれをスライス (slice1 から 18) に入れたので、このコードはケース R まで繰り返されます。 id.bAnswer18: そして、あなたたちはそれが巨大になることに気付くでしょう!! forループを追加するだけで本当に簡単にできることはわかっていますが、機能せず、抜け出せませんか?!
誰かが私を助けてくれませんか??
私のコード:
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.bAnswer1:
if (testing1 != 6) {
String old = tvAnswer1.getText().toString();
tvAnswer1.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
if (testing2 != 6) {
String old = tvAnswer2.getText().toString();
tvAnswer2.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
if (testing3 != 6) {
String old = tvAnswer3.getText().toString();
tvAnswer3.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
if (testing4 != 6) {
String old = tvAnswer4.getText().toString();
tvAnswer4.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
if (testing5 != 6) {
String old = tvAnswer5.getText().toString();
tvAnswer5.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
if (testing6 != 6) {
String old = tvAnswer6.getText().toString();
tvAnswer6.setText(old + slice1);
bAnswer1.setVisibility(View.GONE);
break;
}
break;
case R.id.bAnswer2:
if (testing1 != 6) {
String old = tvAnswer1.getText().toString();
tvAnswer1.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
if (testing2 != 6) {
String old = tvAnswer2.getText().toString();
tvAnswer2.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
if (testing3 != 6) {
String old = tvAnswer3.getText().toString();
tvAnswer3.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
if (testing4 != 6) {
String old = tvAnswer4.getText().toString();
tvAnswer4.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
if (testing5 != 6) {
String old = tvAnswer5.getText().toString();
tvAnswer5.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
if (testing6 != 6) {
String old = tvAnswer6.getText().toString();
tvAnswer6.setText(old + slice2);
bAnswer2.setVisibility(View.GONE);
break;
}
break;