Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package com.artech.myapplication;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.TextView;
  9. import android.widget.Toast;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12. Button button;
  13. EditText edit1,edit2;
  14. TextView txtResult;
  15. Integer num1,num2,result;
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19. setContentView(R.layout.activity_main);
  20. button = findViewById(R.id.btn);
  21. edit1 = findViewById(R.id.et);
  22. edit2 = findViewById(R.id.et1);
  23. txtResult = findViewById(R.id.txtResult);
  24.  
  25. button.setOnClickListener(new View.OnClickListener() {
  26. @Override
  27. public void onClick(View v) {
  28. add();
  29. }
  30. });
  31. }
  32.  
  33. public void add(){
  34. String number1 = edit1.getText().toString().trim();
  35. String number2 = edit2.getText().toString().trim();
  36. if (number1.isEmpty()){
  37. Toast.makeText(this, "No TEXT in first number", Toast.LENGTH_SHORT).show();
  38. }else if (number2.isEmpty()){
  39. Toast.makeText(this, "Enter second number", Toast.LENGTH_SHORT).show();
  40. }else{
  41. num1 = Integer.parseInt(number1);
  42. num2 = Integer.parseInt(number2);
  43. result = num1 + num2;
  44. txtResult.setText("The adding value : "+result);
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement