Thursday, May 16, 2013

Android simple application by adding 2 values

ok this is csharp blog and quit inactive for a long time i have been not posting any thing about c-sharp and that is because i don't much work to do on c-sharp for. but main purpose of this is blog is online codes for programming whether its c-sharp or java or android.
so today i am going to post the complete code of a little android test application.

XML

<?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>

Main Activity
package com.example.test;

import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity 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.activity_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));
     calculate.setText(Double.toString(z));
 }
}

No comments:

Post a Comment

used in operatonal research LP(linear programming) The Simplex Algorithm Simplex method Resolve using the Simple...