Android 개발 메모
String, Int 숫자를 문자로, 문자를 숫자로
Dexx
2015. 6. 8. 15:44
public 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()
}