Thursday, 25 September 2014

Android Bluetooth sample code.


This is a simple and powerful bluetooth app.Using this you can turn_on bluetooth,start discoverable with a simple touch,even turn_off your bluetooth.This will not work on emulator since bluetooth support is not added.



Here the class name is MainActivity. The data fields used are (out,button,button1,button2,mbluetooth bluetoothAdapter).Usually view occupies a rectangular space or area on the screen and used for event handling purpose. For widgets view is the base class used to create interactive UI components findViewById is the override for the method (R.id.out).BluetoothAdapter.getDefaultAdapter() is the method used to perfom bluetooth tasks like device discovery,get query list,instantiate a  bluetoothdevice using MAC address also to create a bluetooth serversocket.

if (mBluetoothAdapter == null) {
out.append("device not supported"); this conditions checks for bluetooth device.If no hardware devices are founding in the device . It displays device not found [Note:This especially happens in android emulator, because there is no support for bluetooth hardware in android emulator].   if (!mBluetoothAdapter.isEnabled()) { when button turn_on is clicked this method will request the bluetooth adapter to enable bluetooth then the activity gets started .

 if (!mBluetoothAdapter.isDiscovering()) {
Context context = getApplicationContext();This returns context for the entire application. We can also use this instead of the current Activitycontext. If user needs a context tied to the lifecycle of the entire application,not just for the current activity.

context.Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT); This method instantiate bluetooth discoverable .We can also set the time for turning on discoverable.

mBluetoothAdapter.disable();This method will turn off the bluetooth and exists the application.

Xml code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"
    tools:context=".MainActivity" >

       The Android compiler considers everything inside the relative layout tag to be a parameter or a customization option until it reaches a closing tag(/>).
android:layout_width="wrap_content"
The wrap_content parameter tiles the content. The layout used for this program is relative layout.


Manifest.xml

In manifest file these to permission’s has to be added in order to start the activity without any crash.

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

 


Java source code



package com.example.bluetooth;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
      private static final int REQUEST_ENABLE_BT = 0;
        private static final int REQUEST_DISCOVERABLE_BT = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    final TextView out=(TextView)findViewById(R.id.out);
    final Button button = (Button) findViewById(R.id.button1);
    final Button button1 = (Button) findViewById(R.id.button2);
    final Button button2 = (Button) findViewById(R.id.button3);
    final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (mBluetoothAdapter == null) {
       out.append("device not supported");
    }
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (!mBluetoothAdapter.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
            }
        }
    });
    button1.setOnClickListener(new View.OnClickListener() {
     @Override
        public void onClick(View arg0) {
            if (!mBluetoothAdapter.isDiscovering()) {
//                   out.append("MAKING YOUR DEVICE DISCOVERABLE");
                   Context context = getApplicationContext();
                   CharSequence text = "MAKING YOUR DEVICE DISCOVERABLE";
                   int duration = Toast.LENGTH_SHORT;

                   Toast toast = Toast.makeText(context, text, duration);
                   toast.show();
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
                startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);
                 
            }
        }
    });
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {  
            mBluetoothAdapter.disable();
//            out.append("TURN_OFF BLUETOOTH");
            Context context = getApplicationContext();
               CharSequence text = "TURNING_OFF BLUETOOTH";
               int duration = Toast.LENGTH_LONG;
               Toast toast = Toast.makeText(context, text, 15);
               toast.show();
            }
    });
}

}



Xml code



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/ic_launcher"
    tools:context=".MainActivity" >

<TextView android:text="" android:id="@+id/out" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="30dp"
        android:layout_marginTop="49dp"
        android:text="TURN_ON" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="27dp"
        android:text="DISCOVERABLE" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/button2"
        android:layout_below="@+id/button2"
        android:layout_marginTop="28dp"
        android:text="TURN_OFF" />

</RelativeLayout>

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.bluetooth"
    android:versionCode="1"
    android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.bluetooth.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>





Download.apk file


http://www.4shared.com/zip/7OHBkCE_ce/Bluetooth.html





Android Copying sample data files into sdcard partition.

Copying sample data files into sdcard partition.

Requirements for copying sample files to SDcard:
1.Android sdk(software development kit).
Link to Download: http://developer.android.com/sdk/index.html

Steps:
1.Connect LAN cable to host and target machines.You should connect to RJ45 port in system.
2.Using ifconfig cmd. Configure the manual ip address for both the machines
Cmd: ifconfig eth0 <ip address> <net mask address> up
ex: ifconfig eth0 192.168.1.15 net mask 255.255.255.0 up
3.Enter into Android sdk path
ex: e:/eclipse/android-sdk/platform-tools/


4.Using adb connect command you can connect host and target
Cmd:adb connect <ip address:port address>
ex:adb connect<192.168.1.15:5555>
Screenshot:

5.Check for connected devices.
Cmd:adb devices
as soon you type this command it will list the connect devices.

6.After connecting devices try to push the files into platform-tools folder.

7.Once the files are copied into platform-tools folder .Use adb push cmd to push the files to target.
Cmd:adb push file name /sdcard/file name..
ex:adb push abc.txt /sdcard/abc.txt


Thursday, 21 March 2013

Android Bluetooth UUID Sample.

This program uses BluetoothAdapter to get default adapter.
Broadcast Intent(ACTION_REQUEST_ENABLE) method is used to turnon bluetooth.

We can get UUID(Universally unique identifier) and MAC address from textview.

Before setting up bluetooth. We need to verify that the bluetooth is supported by the device only then  bluetooth turns on.

To turn on bluetooth the bluetooth adapter is required
(BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
    // Device does not support Bluetooth
}.
 By calling static method .getDefaultAdapter();will return a bluetooth adapter that represents the device.

After getting the bluetooth adapter. We have to enable bluetooth .
This can be done by calling .isEnabled().Even after this if the method returns false.
We can request bluetooth to be enabled by calling startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);

Once bluetooth is enabled .
We can start device discovery .getBondedDevices this will get list of connected devices.

To start discovering devices just call startDiscovery() .
This application has to register a BroadcastReceiver for ACTION_FOUND intent.
Inorder to receive information about all the connected devices.


Finally Out.Append method is used to list the devices and address of the devices.
                     
   

JAVA PROGRAM 


package com.example.bluetoothlist;

import java.util.Set;

import android.os.Bundle;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class Bluetoothlist extends Activity implements OnClickListener, android.view.View.OnClickListener {
    //private static final int REQUEST_ENABLE_BT = 0;
    TextView out;
    Button turnon;
    Button list;
    Button turnoff;
    int REQUEST_ENABLE_BT = 0;
    BluetoothAdapter mBluetoothAdapter = null;
   
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bluetoothlist);
        turnon=(Button)findViewById(R.id.button1);
        list=(Button)findViewById(R.id.list);
        turnoff=(Button)findViewById(R.id.turnoff);
         out = (TextView) findViewById(R.id.add);
       
        final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mBluetoothAdapter.startDiscovery();
        if (mBluetoothAdapter == null) {
         //  out.append("device not supported");
        }
       
       
   

   
      turnon.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (!mBluetoothAdapter.isEnabled()) {
                    Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                    startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
                   
                    Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
                    for (BluetoothDevice device : devices) {
                        out.append("\nFound device: " + device);
                    
                    }
                }
            }
        });
      list.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
             
                    Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
                    for (BluetoothDevice device : devices) {
                       
                        //Menu mArrayAdapter = null;
                        out.append("\nFound device: " + device.getName()+ "\n" +"\nDevice name"+ device.getAddress());
                       
                    
                    }
                }
            });
       
        turnoff.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                  mBluetoothAdapter.disable();
              
            }
        });}

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void onClick(DialogInterface arg0, int arg1) {
        // TODO Auto-generated method stub
       
    }}
   
   

    XML CODE

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Bluetoothlist" >

    <Button
        android:id="@+id/list"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentTop="true"
        android:text="List" />

    <TextView
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_marginTop="52dp"
        android:text="List of devices" />

    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_below="@+id/list"
        android:layout_centerHorizontal="true"
        android:onClick="showMessage"
        android:text="TURN ON BT" />

    <Button
        android:id="@+id/turnoff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/button1"
        android:layout_below="@+id/list"
        android:layout_toRightOf="@+id/list"
        android:text="TURN OFF" />

</RelativeLayout>

 

Manifest File

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bluetoothlist"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
 
   
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.bluetoothlist.Bluetoothlist"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


 
 
 
 

Tuesday, 25 December 2012

Android phone call program.



This program helps you to call . Code used is very simple and easy to understand.


Code: (MainActivity)



package com.example.dialnumber;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;


public class MainActivity extends Activity {
    private Button buttonte1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        buttonte1 = (Button)findViewById(R.id.button1);
        buttonte1.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:123"));
            startActivity(callIntent);


        }});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
Code:(Activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        />

    <Button
        android:id="@+id/button1"
        android:layout_width="500px"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="14dp"
        android:text="CustomerCare" />

</RelativeLayout>

Wednesday, 9 November 2011

Sign your application before posting it to Android Market.

Step 1:Right click your project in eclipse IDE.Select Android Tools.Click export signed applications package.
Step 2:Browse your project path in export window.

Step 3:Enter the password and location in keystore selection window.




Step 4:Enter Alias,password and the number of validity years for your application in keycreation window.




Step 5: Enter the path to save your signed .apk in Destination and key certificate checks .


Saturday, 15 October 2011

Android rating bar.

Designing UI in android is the most interesting part.Here i have made a sample rating bar with some difference with other rating bar.Other rating bar gets the click from Click Listener.But here we can check conditions(          if(num==20){
             mSmallRatingBar.setNumStars(num);
         }in program and give stars to rating bar according to the condition.This sample program can be used for customized rating bar.


Java source code



package rating.bar;



import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;

public class RatingActivity extends Activity {
    RatingBar mSmallRatingBar;
    RatingBar mSmallRatingBar1;
    RatingBar mSmallRatingBar2;
    RatingBar mSmallRatingBar3;
    RatingBar mSmallRatingBar4;
    RatingBar mSmallRatingBar5;
    RatingBar mSmallRatingBar6;
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mSmallRatingBar = (RatingBar) findViewById(R.id.small_ratingbar);
        mSmallRatingBar1 = (RatingBar) findViewById(R.id.small_ratingbar1);
        mSmallRatingBar2 = (RatingBar) findViewById(R.id.small_ratingbar2);
        mSmallRatingBar3 = (RatingBar) findViewById(R.id.small_ratingbar3);
        mSmallRatingBar4 = (RatingBar) findViewById(R.id.small_ratingbar4);
        mSmallRatingBar5 = (RatingBar) findViewById(R.id.small_ratingbar5);
        mSmallRatingBar6 = (RatingBar) findViewById(R.id.small_ratingbar6);
         int num = 20;
         if(num==20){
             mSmallRatingBar.setNumStars(num);
         }
       mSmallRatingBar1.setNumStars(18);
        mSmallRatingBar2.setNumStars(16);
        mSmallRatingBar3.setNumStars(12);
        mSmallRatingBar4.setNumStars(10);
        mSmallRatingBar5.setNumStars(8);
        mSmallRatingBar6.setNumStars(6);
       




      }
}
       
   
       
      
   
xml code


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<RatingBar android:id="@+id/small_ratingbar"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar1"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar2"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar3"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar4"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar5"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
           <RatingBar android:id="@+id/small_ratingbar6"
           style="?android:attr/ratingBarStyleSmall"
           android:background="@drawable/rating"
           android:layout_marginLeft="5dip"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_gravity="center_vertical" />
</LinearLayout>

Source code



Thursday, 13 October 2011

Android Simple calculator program

Hi all,

This is a small calculator program for beginners.With this program you can learn adding buttons to UI,adding sliders to UI.This program uses simple functions like add(),sub(),div(),mul().



JAVA CODE

package simple.calculator;

//import sip.com.calc.R;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

public class SimpleCalculatorActivity extends Activity {
    private EditText txtinput1;
    private EditText txtinput2;
    private EditText txtinput3;
    private Button buttonte;
    private Button buttonte1;
    private Button buttonte2;
    private Button buttonte3;
  //  private Button buttonte4;
    private Button buttonte46;
    private Button buttonte47;
    private Button buttonte48;
    private Button buttonte49;
    private Button buttonte50;
    private Button buttonte51;
    private Button buttonte52;
    private Button buttonte53;
    private Button buttonte54;
    private Button buttonte55;
    private ImageView imageView;
    private double input1 =0;
    private double input2 =0;
    private double input3 =0;
   
   
   
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calc);
        initctrls();
    }
    public void onCreate1(Bundle bundle) {
        super.onCreate(bundle);
        /**Hello World Image JFD*/
        /**BEGIN
        */
        /**Create the ImageView */
        ImageView HelloWorldImageView = new ImageView(this);
        /**Set the ImageView to helloworld.png */
        imageView.setImageResource(R.drawable.icon);
        /**Set the ContentView to the ImageView */
        setContentView(HelloWorldImageView);
        /**END
        */
        }

   private void initctrls(){
       txtinput1 = (EditText)findViewById(R.id.widget41);
       txtinput2 = (EditText)findViewById(R.id.widget43);
       txtinput3 = (EditText)findViewById(R.id.widget45);
       buttonte = (Button)findViewById(R.id.widget56);
       buttonte1 = (Button)findViewById(R.id.widget57);
       buttonte2 = (Button)findViewById(R.id.widget58);
       buttonte3 = (Button)findViewById(R.id.widget59);
       buttonte46 = (Button)findViewById(R.id.widget46);
       buttonte47 = (Button)findViewById(R.id.widget47);
       buttonte48 = (Button)findViewById(R.id.widget48);
       buttonte49 = (Button)findViewById(R.id.widget49);
       buttonte50 = (Button)findViewById(R.id.widget50);
       buttonte51 = (Button)findViewById(R.id.widget51);
       buttonte52 = (Button)findViewById(R.id.widget52);
       buttonte53 = (Button)findViewById(R.id.widget53);
       buttonte54 = (Button)findViewById(R.id.widget54);
       buttonte55 = (Button)findViewById(R.id.widget55);
       buttonte.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ add(); }});
       buttonte1.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ sub(); }});
       buttonte2.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ mul(); }});
       buttonte3.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ div(); }});
       buttonte46.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(1); }});
       buttonte47.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(2); }});
       buttonte48.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(3); }});
       buttonte49.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(4); }});
       buttonte50.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(5); }});
       buttonte51.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(6); }});
       buttonte52.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(7); }});
       buttonte53.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(8); }});
       buttonte54.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(9); }});
       buttonte55.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ num(0); }});
     txtinput1.setInputType(InputType.TYPE_CLASS_NUMBER);
     txtinput2.setInputType(InputType.TYPE_CLASS_NUMBER);
     txtinput3.setInputType(InputType.TYPE_CLASS_NUMBER);
  }
  
   void num(int y){
      // int i =Integer.parseInt(txtinput1.getText().toString());
        if(txtinput1.isFocused()){
           
             txtinput1.append(String.valueOf(y));
        }
        if(txtinput2.isFocused()){
             txtinput2.append(String.valueOf(y));
        }
       
      // txtinput1.setText("1");
      // txtinput2.setText("1");
   }

   private void add(){
       input1=Double.parseDouble(txtinput1.getText().toString());
      
      
      
       input2=Double.parseDouble(txtinput2.getText().toString());
      
       input3 = (input1+input2);
      
       txtinput3.setText(Double.toString(input3));
      
      
   }
   private void sub(){
       input1=Double.parseDouble(txtinput1.getText().toString());
       input2=Double.parseDouble(txtinput2.getText().toString());
       input3=(input1-input2);
       txtinput3.setText(Double.toString(input3));
      
      
   }
   private void mul(){
       input1=Double.parseDouble(txtinput1.getText().toString());
       input2=Double.parseDouble(txtinput2.getText().toString());
       input3=(input1*input2);
       txtinput3.setText(Double.toString(input3));
      
      
   }
   private void div(){
       input1=Double.parseDouble(txtinput1.getText().toString());
       input2=Double.parseDouble(txtinput2.getText().toString());
       input3=(input1/input2);
       txtinput3.setText(Double.toString(input3));
      
      
   }
  
}

Sourcecode

XML CODE



<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<HorizontalScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">
 <ScrollView
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 xmlns:android="http://schemas.android.com/apk/res/android">
<AbsoluteLayout android:id="@+id/AbsoluteLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
<AbsoluteLayout android:id="@+id/AbsoluteLayout1" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/widget40"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I1"
android:layout_x="15px"
android:layout_y="16px"
>
</TextView>
<EditText android:id="@+id/widget41"
android:layout_width="350px"
android:layout_height="80px"
android:inputType="number"
android:text=""
android:textSize="18sp"
android:layout_x="40px"
android:layout_y="16px"
>
</EditText>
<TextView android:id="@+id/widget42"
android:layout_width="350px"
android:layout_height="wrap_content"
android:text="I2"
android:layout_x="15px"
android:layout_y="100px"
>
</TextView>
<EditText android:id="@+id/widget43"
android:layout_width="350px"
android:layout_height="80px"
android:text=""
android:textSize="18sp"
android:layout_x="40px"
android:layout_y="90px"
>
</EditText>
<TextView android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="28px"
android:text="Output"
android:layout_x="2px"
android:layout_y="190px"
>
</TextView>
<EditText android:id="@+id/widget45"
android:layout_width="425px"
android:layout_height="80px"
android:text=""
android:textSize="18sp"
android:layout_x="19px"
android:layout_y="205px"
>
</EditText>
<Button android:id="@+id/widget46"
android:layout_width="55px"
android:layout_height="55px"
android:text="1"
android:layout_x="40px"
android:layout_y="323px"
>
</Button>
<Button android:layout_width="55px"
android:layout_height="55px"
android:text="2"
android:layout_x="138px"
android:layout_y="321px"
android:id="@+id/widget47">
</Button>
<Button android:id="@+id/widget48"
android:layout_width="55px"
android:layout_height="55px"
android:text="3"
android:layout_x="236px"
android:layout_y="321px"
>
</Button>
<Button android:id="@+id/widget49"
android:layout_width="55px"
android:layout_height="55px"
android:text="4"
android:layout_x="40px"
android:layout_y="383px"
>
</Button>
<Button android:id="@+id/widget50"
android:layout_width="55px"
android:layout_height="55px"
android:text="5"
android:layout_x="138px"
android:layout_y="381px"
>
</Button>
<Button android:id="@+id/widget51"
android:layout_width="55px"
android:layout_height="55px"
android:text="6"
android:layout_x="236px"
android:layout_y="381px"
>
</Button>
<Button android:id="@+id/widget52"
android:layout_width="55px"
android:layout_height="55px"
android:text="7"
android:layout_x="40px"
android:layout_y="443px"
>
</Button>
<Button android:id="@+id/widget53"
android:layout_width="55px"
android:layout_height="55px"
android:text="8"
android:layout_x="138px"
android:layout_y="441px"
>
</Button>
<Button android:id="@+id/widget54"
android:layout_width="55px"
android:layout_height="55px"
android:text="9"
android:layout_x="236px"
android:layout_y="441px"
>
</Button>
<Button android:id="@+id/widget55"
android:layout_width="55px"
android:layout_height="55px"
android:text="0"
android:layout_x="138px"
android:layout_y="501px"
>
</Button>
<Button android:layout_width="105px"
android:layout_height="55px"
android:text="+"
android:layout_x="361px"
android:layout_y="321px"
android:id="@+id/widget56">
</Button>
<Button android:id="@+id/widget57"
android:layout_width="105px"
android:layout_height="55px"
android:text="-"
android:layout_x="361px"
android:layout_y="381px"
>
</Button>
<Button android:id="@+id/widget58"
android:layout_width="105px"
android:layout_height="55px"
android:text="*"
android:layout_x="361px"
android:layout_y="441px"
>
</Button>
<Button android:id="@+id/widget59"
android:layout_width="105px"
android:layout_height="55px"
android:text="/"
android:layout_x="361px"
android:layout_y="501px"
>
</Button>
<ImageView android:src="@drawable/icon"
android:layout_width="wrap_content"
 android:layout_height="wrap_content"
  android:layout_x="-5dip"
  android:layout_y="380dip"
   android:id="@+id/imageView1">
   </ImageView>
</AbsoluteLayout>
</AbsoluteLayout>
</ScrollView>
</HorizontalScrollView>

</AbsoluteLayout>