package com.example.cal;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
public class MainActivity extends Activity {
EditText x;
EditText y;
EditText output;
RadioGroup op;
Button exe;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
x = (EditText)findViewById(R.id.x);
y = (EditText)findViewById(R.id.y);
output = (EditText)findViewById(R.id.output);
op = (RadioGroup)findViewById(R.id.op);
exe = (Button)findViewById(R.id.exe);
exe.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String x1 = x.getText().toString();
int x2 = Integer.parseInt(x1);
String y1 = y.getText().toString();
int y2 = Integer.parseInt(y1);
int opId = op.getCheckedRadioButtonId();
String result = "";
if(opId == R.id.add){
result = (x2+y2+"");
}else if(opId == R.id.min){
result = (x2-y2+"");
}else if(opId == R.id.mul){
result = (x2*y2+"");
}else if(opId == R.id.div){
result = (double)x2/(double)y2+"";
}
output.setText(result);
}
});
}
}
제 포스팅이 유용하셨다면 "추천&구독&댓글"누르시고~ 서로 구독해요!
'DIFFERENT > ON's 블로그&IT' 카테고리의 다른 글
안드로이드 앱 개발 환경 구축하기! 앱은 뭘로 만드는 걸까? (0) | 2014.04.19 |
---|---|
아사달, 일러스트 및 사진 이미지 3000점 무료제공!! 무료 이미지 다운 무료 사진 일러스트! (4) | 2014.04.16 |
안드로이드 앱만들기! 계산기 어플 코드 더하기 연산! (0) | 2014.04.10 |
트랙백이란? 트랙백 처음 달린 날 기념하기ㅋㅋ 트랙백 의미 뜻 정의! (2) | 2014.03.28 |
<첫번째 드림>티스토리 초대장 3장 배포합니다. (마감) (29) | 2014.01.14 |