Sunday, 16 June 2019

Develop an Android application which displays a form to get two numbers from user using appropriate widget. Toast the value of addition of the given to numbers. Eg. 2+3=5 Toast the answer 5. Mobile Computing and Wireless Communication (170702) GTU


               Code :

          <?xml version="1.0" encoding="utf-8"?>
          <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:orientation="vertical"
              tools:context=".AddUP">
           
              <EditText
                  android:id="@+id/value1"
                  android:layout_width="350dp"
                  android:layout_height="wrap_content"
                  android:ems="10"
           
                  android:hint="Enter 1st Number"
                  android:inputType="number" />
           
              <EditText
                  android:id="@+id/value2"
                  android:layout_width="350dp"
                  android:layout_height="wrap_content"
                  android:ems="10"
           
                  android:hint="Enter 2nd Number"
                  android:inputType="number" />
           
              <Button
                  android:id="@+id/submit"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:text="Submit" />
           
          </LinearLayout>
           
          package com.example.devang.exhello;
           
          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.Toast;
          public class AddUP extends AppCompatActivity {
              Button submit;
              EditText t1,t2;
              @Override
              protected void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  setContentView(R.layout.activity_add_up);
                  submit = findViewById(R.id.submit);
                  t1 = findViewById(R.id.value1);
                  t2 = findViewById(R.id.value2);
           
                  submit.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          int sum = (Integer.parseInt(t1.getText().toString()) + Integer.parseInt(t2.getText().toString()));
                          Toast.makeText(getApplicationContext(),"Addition is: "+Integer.toString(sum),Toast.LENGTH_LONG).show();
                      }
                  });
              }
          }

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...