package com.example.ryan.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText editText1;
EditText editText2;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button1=(Button)findViewById(R.id.button1);
Button button2=(Button)findViewById(R.id.button2);
Button button3=(Button)findViewById(R.id.button3);
Button button4=(Button)findViewById(R.id.button4);
//way1
// button1.setOnClickListener(new View.OnClickListener(){
// public void onClick(View v){
// Toast.makeText(getApplicationContext(),"버튼이 눌러졌습니다",Toast.LENGTH_SHORT).show();
// String num1=editText1.getText().toString();
// String num2=editText2.getText().toString();
// int result =Integer.parseInt(num1)+Integer.parseInt(num2);
// textView.setText(String.valueOf(result));
// }
// });
editText1 = (EditText) findViewById(R.id.editText1);
editText2 = (EditText) findViewById(R.id.editText2);
textView = (TextView) findViewById(R.id.textView);
}
public void onClickButton1(View v) {
String num1 = editText1.getText().toString();
String num2 = editText2.getText().toString();
int result = Integer.parseInt(num1) + Integer.parseInt(num2);
textView.setText(String.valueOf(result));
}
public void onClickButton2(View v) {
String num1 = editText1.getText().toString();
String num2 = editText2.getText().toString();
int result = Integer.parseInt(num1) - Integer.parseInt(num2);
textView.setText(String.valueOf(result));
}
public void onClickButton3(View v) {
String num1 = editText1.getText().toString();
String num2 = editText2.getText().toString();
int result = Integer.parseInt(num1) * Integer.parseInt(num2);
textView.setText(String.valueOf(result));
}
public void onClickButton4(View v){
String num1=editText1.getText().toString();
String num2=editText2.getText().toString();
int result =Integer.parseInt(num1)/Integer.parseInt(num2);
textView.setText(String.valueOf(result));
}
}