18 개의 버튼 (bAnswer1 ~ bAnswer18)과 6 개의 텍스트 뷰 (tvAnswer1 ~ 6)가있는 앱을 만들고 있어요. 내 뜻은 6 단어를 2 단어 3 개 (예 : 버튼, 연속)로 슬라이싱하는 것입니다.이 단어를 6 단어로 나누어 슬라이스 (슬라이스 1 ~ 18)에 넣으면이 코드는 R 경우에 반복됩니다. id.bAnswer18 : 그리고 너희들은 휴 (hugh)가 될 것이라는 것을 알아 차릴 것이다 !! 나는 for 루프를 추가함으로써 정말 간단하게 만들 수 있다는 것을 알고 있지만, 작동하지 않을 것이고 나올 수 없다.안드로이드 - 이것을 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;
주위에 for 루프를 넣으십시오. 이미 말했듯이, 당신은 이미 그것을 단순하게 만드는 법을 이미 알고 있습니다, 그래서 그것을 단순하게 만드십시오. – Shark
6 개 또는 18 개의 필드 대신 단추 배열과 다른 textviews 배열이 있어야합니다. 나머지는 사소 할 것입니다. –
여기 왜 필요합니까? – TheWhiteRabbit