티스토리 뷰
String, Int 숫자를 문자로, 문자를 숫자로
Dexx 2015. 6. 8. 15:44public void onClick(View v) {
String aStr = editText2.getText().toString();
String bStr = editText3.getText().toString();
int a = 0;
int b = 0;
try {
a = Integer.parseInt(aStr); // 문자를 숫자로 변경 Integer.parseInt()
b = Integer.parseInt(bStr);
} catch (Exception ex) {
ex.printStackTrace();
}
MyCalculator calculator = new MyCalculator();
int result = calculator.add(a,b);
editText3.setText(String.valueOf(result)); // 숫자를 문자로 변경 String.valueOf()
}
'Android 개발 메모' 카테고리의 다른 글
뒤로가기 두번 누르면 종료 (0) | 2015.06.09 |
---|---|
예외 처리 throws (0) | 2015.06.08 |
Intent 데이터 전달 (0) | 2015.06.08 |
댓글