Guest User

Untitled

a guest
Dec 10th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  2. private Button plus;
  3. private Button minus;
  4. private Button umnogenie;
  5. private Button delenie;
  6. private TextView text1;
  7. private EditText vvod1;
  8. private EditText vvod2;
  9. private double a,b;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15. this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  16. plus = (Button) findViewById(R.id.button9);
  17. minus= (Button) findViewById(R.id.button10);
  18. delenie= (Button) findViewById(R.id.button11);
  19. umnogenie= (Button) findViewById(R.id.button12);
  20. text1= (TextView) findViewById(R.id.textView);
  21. vvod1= (EditText) findViewById(R.id.editText);
  22. vvod2= (EditText) findViewById(R.id.editText2);
  23.  
  24. plus.setOnClickListener(this);
  25. minus.setOnClickListener(this);
  26. delenie.setOnClickListener(this);
  27. umnogenie.setOnClickListener(this);
  28.  
  29. vvod1.addTextChangedListener(new TextWatcher() {
  30. @Override
  31. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  32.  
  33. }
  34.  
  35.  
  36.  
  37. @Override
  38. public void onTextChanged(CharSequence s, int start, int before, int count) {
  39. if (s == null)
  40. a= 0;
  41. else
  42. a = Integer.parseInt(s.toString());
  43. }
  44.  
  45.  
  46. @Override
  47. public void afterTextChanged(Editable s) {
  48.  
  49. }
  50. });
  51. vvod2.addTextChangedListener(new TextWatcher() {
  52. @Override
  53. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  54.  
  55. }
  56.  
  57. @Override
  58. public void onTextChanged(CharSequence s, int start, int before, int count) {
  59. if (s == null)
  60. b= 0;
  61. else
  62. b = Integer.parseInt(s.toString());
  63. }
  64.  
  65. @Override
  66. public void afterTextChanged(Editable s) {
  67.  
  68. }
  69. });
  70.  
  71. }
  72.  
  73. @Override
  74. public void onClick(View v) {
  75. switch (v.getId()){
  76.  
  77. case R.id.button9: text1.setText(String.valueOf(a+b));
  78. break;
  79. case R.id.button10: text1.setText(String.valueOf(a-b));
  80. break;
  81. case R.id.button11: text1.setText(String.valueOf(a/b));
  82. break;
  83. case R.id.button12: text1.setText(String.valueOf(a*b));
  84. break;
  85. }
  86. }
  87. }
Add Comment
Please, Sign In to add comment