안드로이드 프로그래밍 소스에 대해 질문해도될런지 ..?
public class MainActivity extends ActionBarActivity {
EditText edText1, edText2;
Button btnAdd,btnSub,btnMul,btnDiv;
TextView tvResult;
String num1, num2;
Integer result; //변수 선언
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
edText1=(EditText)findViewById(R.id.edText1);
edText2=(EditText)findViewById(R.id.edText2);
btnAdd=(Button)findViewById(R.id.btnAdd);
btnSub=(Button)findViewById(R.id.btnSub);
btnMul=(Button)findViewById(R.id.btnMul);
btnDiv=(Button)findViewById(R.id.btnDiv);
tvResult=(TextView)findViewById(R.id.tvResult); //변수에 위젯 연동
btnAdd.setOnClickListener(new View.OnClickListener() { //더하기버튼 클릭시
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
num1=edText1.getText().toString();
num2=edText2.getText().toString();
result=Integer.parseInt(num1)+Integer.parseInt(num2);
tvResult.setText("계산 결과 : " + result);
}
});
ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
소스는 이렇습니다.
안드로이드 이클립스를 이용해서 계산기를 만들었는데,
btnAdd를 누르면 edText1, edText2에 입력한 값이 더한 값이 아래에 출력이 나오는데
추가하고싶은 부분은 edText1나 edText2에 값을 입력안하고 버튼을 눌렀을때 토스트메시지로 오류메시지를 띄울려고 합니다만 ..
if문 switch문 isEmpty()등등 별걸 다해봤는데 되지가 않네요 ...
어떤걸 추가해야할지 ...
죄송합니다, 글이 두개가 올라갔네요 ...
죄송합니다, 글이 두개가 올라갔네요 ...
댓글 달기