code for app
unknown
java
3 years ago
1.7 kB
42
Indexable
package com.example.myapplication; import androidx.appcompat.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 { // declare variables first EditText number1,number2; Button addtionbtn; TextView result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // getting resource by their id's number1 = findViewById(R.id.et_number1); number2 = findViewById(R.id.et_number2); addtionbtn = findViewById(R.id.btn_addition); result = findViewById(R.id.tv_result); } // this function will be called after clicking on the button public void addition(View view) { // converting edit text to string type // getText() method is used to get the text // toString() method is used to convert that text into string String num1 = number1.getText().toString(); String num2 = number2.getText().toString(); // converting variables into double double doublenumber1 = Double.parseDouble(num1); double doublenumber2 = Double.parseDouble(num2); // showing text into textView result.setText(Double.toString(doublenumber1+doublenumber2)); // creating Toast Toast.makeText(this,"Your addition is :"+(doublenumber1+doublenumber2),Toast.LENGTH_LONG).show(); } }
Editor is loading...