Saturday, 16 June 2012

Addition example in Android


Addition Activity in Android

package com.nam;




import android.app.Activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NamrathaaddActivity extends Activity {
private static final String TAG = NamrathaaddActivity.class.getSimpleName();
private EditText et1,et2;
private Button bt1;
private TextView tv1;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        et1 = (EditText) findViewById(R.id.editText1);
        et2 = (EditText)findViewById(R.id.editText2);
        bt1 = (Button) findViewById(R.id.button1);
        tv1 = (TextView)findViewById(R.id.textView1);
        bt1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Integer num3;
String str1 = et1.getText().toString();
Log.i(TAG,"c log example" + str1);
String str2 = et2.getText().toString();
num3 =  Integer.parseInt(str1)+Integer.parseInt(str2);

tv1.setText(num3.toString());
} catch (NumberFormatException e) {
// TODO Auto-generated catch block

e.printStackTrace();
}

}
});






}

    }




main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPersonName" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...