Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- private Button plus;
- private Button minus;
- private Button umnogenie;
- private Button delenie;
- private TextView text1;
- private EditText vvod1;
- private EditText vvod2;
- private double a,b;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- plus = (Button) findViewById(R.id.button9);
- minus= (Button) findViewById(R.id.button10);
- delenie= (Button) findViewById(R.id.button11);
- umnogenie= (Button) findViewById(R.id.button12);
- text1= (TextView) findViewById(R.id.textView);
- vvod1= (EditText) findViewById(R.id.editText);
- vvod2= (EditText) findViewById(R.id.editText2);
- plus.setOnClickListener(this);
- minus.setOnClickListener(this);
- delenie.setOnClickListener(this);
- umnogenie.setOnClickListener(this);
- vvod1.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if (s == null)
- a= 0;
- else
- a = Integer.parseInt(s.toString());
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- vvod2.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- if (s == null)
- b= 0;
- else
- b = Integer.parseInt(s.toString());
- }
- @Override
- public void afterTextChanged(Editable s) {
- }
- });
- }
- @Override
- public void onClick(View v) {
- switch (v.getId()){
- case R.id.button9: text1.setText(String.valueOf(a+b));
- break;
- case R.id.button10: text1.setText(String.valueOf(a-b));
- break;
- case R.id.button11: text1.setText(String.valueOf(a/b));
- break;
- case R.id.button12: text1.setText(String.valueOf(a*b));
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment