Login

Lost Password?

Register

Register
How Android Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.


Thread Rating:
  • 11 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Simple Android Application For Adding Two Numbers
Author Message

uvweep
Junior Member
**



Posts:   17
Joined:   May 2013
Reputation:   0
Status:   Offline
#1
A Simple Android Application For Adding Two Numbers - 01-31-2014, 03:52 PM,


Hi, I am practising on android app I've made an simple app for adding two number:

Firstly modifying the .xml file in addition/res/layout/main.xml which is responsible for the layout of the application.

Code:
<?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout android:id="@+id/widget0"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TextView android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="ADDITION OF NUMBERS"
     android:id="@+id/textView1"
     android:layout_x="73dip"
     android:layout_y="28dip"></TextView>
    <TextView android:layout_width="wrap_content"
    android:layout_x="36dip"
    android:layout_height="wrap_content"
    android:text="First Amount"
    android:id="@+id/textView2"
    android:layout_y="80dip"></TextView>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="172dip"
    android:id="@+id/amount1"
    android:layout_height="wrap_content"
    android:layout_y="62dip"></EditText>
    <TextView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Second Amount"
    android:id="@+id/textView3"
    android:layout_x="36dip"
    android:layout_y="169dip"></TextView>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="169dip"
    android:id="@+id/amount2"
    android:layout_height="wrap_content"
    android:layout_y="152dip"></EditText>
    <Button android:layout_width="wrap_content"
    android:id="@+id/calculate"
    android:layout_x="41dip"
    android:layout_height="wrap_content"
    android:text="Calculate"
    android:layout_y="232dip"></Button>
    <EditText android:text=""
    android:layout_width="wrap_content"
    android:layout_x="172dip"
    android:id="@+id/tt"
    android:layout_height="wrap_content"
    android:layout_y="232dip"></EditText>
    </AbsoluteLayout>

Now modify the addition/src/com.example.addition/addition.java as shown belowSadcom.example.addition is the package name)

Code:
package com.example.addition;


import android.app.Activity;

import android.os.Bundle;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Button;

import android.view.View;


public class test extends Activity
{
  EditText amount1;
  EditText amount2;
  TextView tt;
  Button calculate;
  double x=0;
  double y=0;
  double z=0;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      initControls();
  }
  private void initControls()
  {
      amount1=(EditText)findViewById(R.id.amount1);
      amount2=(EditText)findViewById(R.id.amount2);
      tt=(TextView)findViewById(R.id.tt);
      calculate=(Button)findViewById(R.id.calculate);
      calculate.setOnClickListener(new Button.OnClickListener()
      {public void onClick
      (View  v) { calculate();}});
  }
  private void calculate()
  {
      x=Double.parseDouble(amount1.getText().toString());
      y=Double.parseDouble(amount2.getText().toString());
      z=x+y;
      tt.setText(Double.toString(z));
  }
}


We are done.Now run the application in the android emulator.
Quote this message in a reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Introducing Android Wear Developer Preview Android Addict 0 604 04-02-2014, 03:47 PM
Last Post: Android Addict
  What are some general tips on improving overall performance of an Android phone? IPhoneExpert 2 755 03-02-2014, 07:28 PM
Last Post: minuvweyna
  How to create a simple iPhone app? Lulu Bandola 0 497 02-01-2014, 04:09 PM
Last Post: Lulu Bandola
  How to create a simple Menu app in android? Chiranjivi Nagpal 0 521 01-30-2014, 12:46 PM
Last Post: Chiranjivi Nagpal
  How to Develop Android Apps - Playing with your (MediaPlayer) Ashish Bathnotra 0 685 09-19-2013, 06:18 PM
Last Post: Ashish Bathnotra
  Develop Android App - Simple Calculator Application malaxophobic 0 587 09-16-2013, 12:37 PM
Last Post: malaxophobic
  [Tutorial]How to make Talking SMS app in Android Sameer Ahmed 0 1,009 09-16-2013, 11:28 AM
Last Post: Sameer Ahmed
  Which are the best books available in the market for Beginners in Android Programming Victor Creed 1 628 09-16-2013, 11:01 AM
Last Post: udayan choudhuri
  [Video Tutorial] Inside theAndroid Application Framework in depth udayan choudhuri 0 752 09-16-2013, 10:57 AM
Last Post: udayan choudhuri
  Recommended Android Books PAUL LIMON 0 826 09-13-2013, 12:43 PM
Last Post: PAUL LIMON

Forum Jump:


Users browsing this thread: 1 Guest(s)