안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요!
요새 안드로이드를 배우고있는 초짜입니다.
코드를 짜다가 궁금한점이 생겨서 질문을 하게 되었습니다.
제가 텍스트뷰1에 text1.setText("100")
텍스트뷰2에는 text2.setText("200")
텍스트뷰3에는 text3.setText("300")
텍스트뷰4에는 text4.setText("400")
을 넣고 텍스트뷰 모두안에 잇는 값을 정수화해서더한후 다시 스트링화 하여 text5에 넣으려면
String str1=text1.getText().toString();
int a1=Integer.valueOf(str1);
String str2=text2.getText().toString();
int a2=Integer.valueOf(str2);
String str3=text3.getText().toString();
int a3=Integer.valueOf(str3);
String str4=text4.getText().toString();
int a4=Integer.valueOf(str4);
int a6=a1+a2+a3+a4;
String str5=String.valueOf(a6);
int a1=Integer.valueOf(str1);
String str2=text2.getText().toString();
int a2=Integer.valueOf(str2);
String str3=text3.getText().toString();
int a3=Integer.valueOf(str3);
String str4=text4.getText().toString();
int a4=Integer.valueOf(str4);
int a6=a1+a2+a3+a4;
String str5=String.valueOf(a6);
text5.setText(str5)
이러면 되는거 같은데
텍스트뷰가 몇개 있는지 모를때 어떻게 코드를 짜 넣어야 되는지 아무리 머리를 싸매도 잘 모르겠습니다 ㅜㅠㅜㅠ
고수분들 좀 도와주세요 ㅜㅠ
ArrayList에 넣고 for 문으로 돌리심 될듯...