Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.artech.myapplication;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- Button button;
- EditText edit1,edit2;
- TextView txtResult;
- Integer num1,num2,result;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- button = findViewById(R.id.btn);
- edit1 = findViewById(R.id.et);
- edit2 = findViewById(R.id.et1);
- txtResult = findViewById(R.id.txtResult);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- add();
- }
- });
- }
- public void add(){
- String number1 = edit1.getText().toString().trim();
- String number2 = edit2.getText().toString().trim();
- if (number1.isEmpty()){
- Toast.makeText(this, "No TEXT in first number", Toast.LENGTH_SHORT).show();
- }else if (number2.isEmpty()){
- Toast.makeText(this, "Enter second number", Toast.LENGTH_SHORT).show();
- }else{
- num1 = Integer.parseInt(number1);
- num2 = Integer.parseInt(number2);
- result = num1 + num2;
- txtResult.setText("The adding value : "+result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement