티스토리 뷰
소스코드
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 package com.example.sh415.project4_1;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;import android.widget.Toast;import static com.example.sh415.project4_1.R.id.btn0;import static com.example.sh415.project4_1.R.id.btn1;import static com.example.sh415.project4_1.R.id.btn2;import static com.example.sh415.project4_1.R.id.btn3;import static com.example.sh415.project4_1.R.id.btn4;import static com.example.sh415.project4_1.R.id.btn5;import static com.example.sh415.project4_1.R.id.btn6;import static com.example.sh415.project4_1.R.id.btn7;import static com.example.sh415.project4_1.R.id.btn8;import static com.example.sh415.project4_1.R.id.btn9;public class TabActivity extends AppCompatActivity {EditText num1, num2;Button Add,Sub,Multi,Div;Button bbtn0;Button bbtn1; TextView result;Button bbtn2;Button bbtn3;Button bbtn4;Button bbtn5;Button bbtn6;Button bbtn7;Button bbtn8;Button bbtn9;String strnum1,strnum2;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.testtable);num1 = (EditText)findViewById(R.id.num1);num2= (EditText)findViewById(R.id.num2);Add = (Button)findViewById(R.id.btnAdd);Sub = (Button)findViewById(R.id.btnSub);Multi = (Button)findViewById(R.id.btnMulti);Div = (Button)findViewById(R.id.btnDiv);result = (TextView)findViewById(R.id.result);bbtn0 = (Button)findViewById(btn0);bbtn1 = (Button)findViewById(btn1);bbtn2 = (Button)findViewById(btn2);bbtn3 = (Button)findViewById(btn3);bbtn4 = (Button)findViewById(btn4);bbtn5 = (Button)findViewById(btn5);bbtn6 = (Button)findViewById(btn6);bbtn7 = (Button)findViewById(btn7);bbtn8 = (Button)findViewById(btn8);bbtn9 = (Button)findViewById(btn9);bbtn0.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn0.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn0.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn1.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn1.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn1.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn2.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn2.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn2.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn3.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn3.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn3.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn4.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn4.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn4.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn5.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn5.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn5.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn6.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn6.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn6.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn7.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn7.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn7.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn8.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn8.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn8.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});bbtn9.setOnClickListener(new View.OnClickListener(){public void onClick(View v){if(num1.isFocused() == true){strnum1 = num1.getText().toString()+ bbtn9.getText().toString();num1.setText(strnum1);}else if(num2.isFocused() == true){strnum2 = num2.getText().toString()+ bbtn9.getText().toString();num2.setText(strnum2);}else{Toast.makeText(getApplicationContext(),"먼저 에디트를 선택하세요",Toast.LENGTH_LONG).show();}}});Add.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {result.setText("계산 결과는 :" + (Integer.parseInt(num1.getText().toString())+Integer.parseInt(num2.getText().toString())));}});Sub.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {result.setText("계산 결과는 :" + (Integer.parseInt(num1.getText().toString())-Integer.parseInt(num2.getText().toString())));}});Multi.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {result.setText("계산 결과는 :" + (Integer.parseInt(num1.getText().toString())*Integer.parseInt(num2.getText().toString())));}});Div.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {result.setText("계산 결과는 :" + (Integer.parseInt(num1.getText().toString())/Integer.parseInt(num2.getText().toString())));}});}}cs
결과 화면
덧셈 결과
뺄셈 결과
곱셈 결과
나눗셈 결과
'IT > Android' 카테고리의 다른 글
[Android] 코난과 함께하는 사용자 뷰(Custom View) 구현하기! 예제 1 (0) | 2017.07.31 |
---|---|
[Android] 코난과 함께하는 Spinner view(스피너뷰) 구현하기! (0) | 2017.07.31 |
[Android] Listview(리스트뷰) 구현하기! (0) | 2017.07.31 |
[Android] 테이블 레이아웃 (TableLayout) (0) | 2017.07.24 |
[Android] 렐러티브레이아웃(상대 레이아웃) RelativeLayout (0) | 2017.07.24 |
댓글