Friday, May 16, 2014

Check Internet Cunnection are abailable or not in Background android

layout:-

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="96dp"
        android:layout_marginTop="30dp"
        android:text="Checked " />

</RelativeLayout>



Activity:-

package com.example.downloadfilefromurltooffline;

import android.app.Activity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

     TextView tbdatacheck;
    Button btndatadownload;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       tbdatacheck=(TextView)findViewById(R.id.textView1);
     
      
      
       if(isConnected()){
           tbdatacheck.setBackgroundColor(0xFF00CC00);
           tbdatacheck.setText("You are conncted");
       }
       else{
           tbdatacheck.setText("You are NOT conncted");
       }

    } 
    public boolean isConnected(){
        ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
            if (networkInfo != null && networkInfo.isConnected())
                return true;
            else
                return false;   
    }
}

manifest:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.downloadfilefromurltooffline"
    android:versionCode="1"
    android:versionName="1.0" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.downloadfilefromurltooffline.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>
Thanks Friends

Xml parsing with SAXParser listitem data selected and item position gows to single activity Android




Layouts:-
activitymain

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
  <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/listview"
        android:cacheColorHint="@android:color/transparent"
        android:dividerHeight="2dp"
        />
</RelativeLayout>

listitem:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
<TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="amit"
      
        android:textSize="18dp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="amit"
       
        android:textSize="18dp" />

    <TextView
        android:id="@+id/quali"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="amit"
     
        android:textSize="18dp" />
</LinearLayout>



singledata:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
<TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="abc"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="abc"
        android:textSize="18dp" />

    <TextView
        android:id="@+id/quali"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="abc"
     
        android:textSize="18dp" />
</LinearLayout>

MainActivity:-

package offlinereaddata.amit.com;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
     private ListView listView;
     private ListAdapter adapter;
        static final String KEY_MAIN = "main"; // parent node
        static final String KEY_ID = "id";
        static final String KEY_NAME = "name";
        static final String KEY_ADDRESS = "cost";
        static final String KEY_QUA = "qua";
          ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
            ArrayAdapter<String> adapterBusinessType;      
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.listview);
           try {
               SAXParserFactory saxparser = SAXParserFactory.newInstance();
               SAXParser parser = saxparser.newSAXParser();
               XMLReader xmlReader = parser.getXMLReader();
               final ParsingClass pc = new ParsingClass();
               xmlReader.setContentHandler(pc);
               InputStream is = getAssets().open("abc.xml");
               xmlReader.parse(new InputSource(is));
               BindingData bindingData = new BindingData(this, pc.name,
               pc.address, pc.qua);
              
              
               adapterBusinessType = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item);
               
              
               listView.setAdapter(bindingData);
              
           
                listView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View view,
                              int position, long id) {
               
                       
                       
                         int pos=position;
                            BindingData entry= (BindingData) parent.getAdapter().getItem(position);
                                                         String names=pc.name.get(position);
                                                         String address=pc.address.get(position);
                                                         String qualification=pc.qua.get(position);
                                                        

                          Intent intent=new Intent(MainActivity.this,SingleMenuItemActivity.class);
                          intent.putExtra("Name", names);
                          intent.putExtra("Address", address);
                          intent.putExtra("Qualification", qualification);
                         
                         
                         startActivity(intent);
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                       
                        /*    String name,address,qualification;
                         String item = ((AdapterView<ListAdapter>) adapter).getItemAtPosition(position).toString();
                    //    name= menuItems.getString(menuItems.getColumnIndex(pc.name)));
           
                        name=pc.name.toString();
                        address=pc.address.toString();
                        qualification=pc.qua.toString();
                       
                        Toast.makeText(getApplicationContext(),""+item,Toast.LENGTH_LONG).show();
           
                        Toast.makeText(getApplicationContext(),"data="+name,Toast.LENGTH_LONG).show();
                       
                   
                          Intent intent=new Intent(getApplicationContext(),SingleMenuItemActivity.class);    
                          intent.putExtra(name, name);
                          intent.putExtra(address,address);
                          intent.putExtra(qualification, qualification);
                        //  Toast.makeText(getApplicationContext(),"data="+intent,Toast.LENGTH_LONG).show();
                          startActivity(intent); 
                          */
                    }
                });
              
              } catch (Exception e) {
               e.getMessage();
              }
             }


}

BindingData Class:-

package offlinereaddata.amit.com;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BindingData extends BaseAdapter{
    ArrayList<String> name;
     ArrayList<String> address;
     ArrayList<String> qua;
     LayoutInflater inflater;

     public BindingData() {

     }

     public BindingData(Activity act, ArrayList<String> name,
       ArrayList<String> add, ArrayList<String> qua) {
      this.name = name;
      this.address = add;
      this.qua = qua;
      inflater = (LayoutInflater) act
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     }

     @Override
     public int getCount() {
      return name.size();
     }

     @Override
     public String getItem(int position) {
      return null;
     }

     @Override
     public long getItemId(int position) {
      return 0;
     }

     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
      Holder holder;
      if (convertView == null) {
       holder = new Holder();
       convertView = inflater.inflate(R.layout.list_item, null);
       holder.txtName = (TextView) convertView.findViewById(R.id.name);
       holder.txtAddress = (TextView) convertView
         .findViewById(R.id.address);
       holder.txtQua = (TextView) convertView.findViewById(R.id.quali);
       convertView.setTag(holder);
      } else {
       holder = (Holder) convertView.getTag();
      }
      holder.txtName.setText(Html.fromHtml("" + name.get(position)));
      holder.txtAddress.setText(Html.fromHtml("<b>Address : </b>"
        + address.get(position)));
      holder.txtQua.setText(Html.fromHtml("<b>Qualification : </b>"
        + qua.get(position)));

      return convertView;
     }

     private class Holder {
      TextView txtName, txtAddress, txtQua;
     }
    }

parser class:-

package offlinereaddata.amit.com;

import java.util.ArrayList;
import java.util.jar.Attributes;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ParsingClass extends DefaultHandler {

     ArrayList<String> name = new ArrayList<String>();
     ArrayList<String> address = new ArrayList<String>();
     ArrayList<String> qua = new ArrayList<String>();

     public void startElement(String uri, String localName, String qName,
       Attributes attributes) throws SAXException {
      super.startElement(uri, localName, qName, (org.xml.sax.Attributes) attributes);
      if (localName.equalsIgnoreCase("name")) {
       tempStore = "";
      } else if (localName.equalsIgnoreCase("address")) {
       tempStore = "";
      } else if (localName.equalsIgnoreCase("qua")) {
       tempStore = "";
      }else{
       tempStore = "";
      }
     }

     @Override
     public void endElement(String uri, String localName, String qName)
       throws SAXException {
      super.endElement(uri, localName, qName);
      if (localName.equalsIgnoreCase("name")) {
       name.add(tempStore);
      } else if (localName.equalsIgnoreCase("address")) {
       address.add(tempStore);
      } else if (localName.equalsIgnoreCase("qua")) {
       qua.add(tempStore);
      }
      tempStore = "";
     }

     private String tempStore = "";

     @Override
     public void characters(char[] ch, int start, int length)
       throws SAXException {
      super.characters(ch, start, length);
      tempStore += new String(ch, start, length);
     }
    }

Singledataitemclass:-

package offlinereaddata.amit.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;


public class SingleMenuItemActivity extends Activity{

 TextView tbname,tbaddress,tbqualification;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.singledata);
        Intent in = getIntent();
        String name = in.getStringExtra("Name");
        String address = in.getStringExtra("Address");
        String qualification = in.getStringExtra("Qualification");
        tbname=(TextView)findViewById(R.id.name);
        tbaddress=(TextView)findViewById(R.id.address);
        tbqualification=(TextView)findViewById(R.id.quali);
    
        tbname.setText(name);
        tbaddress.setText(address);
        tbqualification.setText(qualification);
       
      
       
    }
}

manifest.xml

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="offlinereaddata.amit.com.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>
         <activity
            android:name="offlinereaddata.amit.com.SingleMenuItemActivity"
            android:label="@string/app_name" >
       </activity>
    </application>

</manifest>
 and Xml in AssetFolder is:-

abc.xml:-


<main>
 <student>
  <name> Amit sharma</name>
  <address>mathura</address>
  <qua> MCA</qua>
 </student>
 <student>
  <name> Amit kumar sharma </name>
  <address> Raya :- Nagla Bhima </address>
  <qua> BCA </qua>
 </student>
 <student>
  <name> Amit</name>
  <address>16 nagla bhima </address>
  <qua> B Tech</qua>
 </student>
 <student>
  <name> ABC You are</name>
  <address>This is my address</address>
  <qua> B.Com </qua>
 </student>
 <student>
  <name> HIMCS</name>
  <address> MCA MATHURA</address>
  <qua> BCA </qua>
 </student>
 <student>
  <name> Mathura Krishana</name>
  <address> This is me </address>
  <qua> M Tech </qua>
 </student>
</main>






Thans To my All friends This is a Sample of offline xml parsing these noots are not net or any publisher not publish this kind of noot and tutorials This is Different from others 


..........






Thursday, May 15, 2014

xml parsing Using SAXParser Read Xml from assets folder or offline parsing

Assets Folder:- abc.xml File


<main>
 <student>
  <name> Amit sharma</name>
  <address>mathura</address>
  <qua> MCA</qua>
 </student>
 <student>
  <name> Amit kumar sharma </name>
  <address> Raya :- Nagla Bhima </address>
  <qua> BCA </qua>
 </student>
 <student>
  <name> Amit</name>
  <address>16 nagla bhima </address>
  <qua> B Tech</qua>
 </student>
 <student>
  <name> ABC You are</name>
  <address>This is my address</address>
  <qua> B.Com </qua>
 </student>
 <student>
  <name> HIMCS</name>
  <address> MCA MATHURA</address>
  <qua> BCA </qua>
 </student>
 <student>
  <name> Mathura Krishana</name>
  <address> This is me </address>
  <qua> M Tech </qua>
 </student>
</main>


Layout mainActivity:-

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
  <ListView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/listview"
        android:cacheColorHint="@android:color/transparent"
        android:dividerHeight="2dp"
        />
</RelativeLayout>

listitemacticity:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
<TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sameer Ahmad"
      
        android:textSize="18dp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sameer Ahmad"
       
        android:textSize="18dp" />

    <TextView
        android:id="@+id/quali"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sameer Ahmad"
     
        android:textSize="18dp" />
</LinearLayout>

MainActivity:-

package offlinereaddata.amit.com;

import java.io.InputStream;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class MainActivity extends Activity {
     private ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.listview);
        bindDataToListing();
    
    }
    private void bindDataToListing() {
        // TODO Auto-generated method stub
         try {
               SAXParserFactory saxparser = SAXParserFactory.newInstance();
               SAXParser parser = saxparser.newSAXParser();
               XMLReader xmlReader = parser.getXMLReader();
               ParsingClass pc = new ParsingClass();
               xmlReader.setContentHandler(pc);
               InputStream is = getAssets().open("abc.xml");
               xmlReader.parse(new InputSource(is));
               BindingData bindingData = new BindingData(this, pc.name,
                 pc.address, pc.qua);
               listView.setAdapter(bindingData);
              } catch (Exception e) {
               e.getMessage();
              }
             }

}

class BindingData:-

package offlinereaddata.amit.com;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class BindingData extends BaseAdapter{
    ArrayList<String> name;
     ArrayList<String> address;
     ArrayList<String> qua;
     LayoutInflater inflater;

     public BindingData() {

     }

     public BindingData(Activity act, ArrayList<String> name,
       ArrayList<String> add, ArrayList<String> qua) {
      this.name = name;
      this.address = add;
      this.qua = qua;
      inflater = (LayoutInflater) act
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     }

     @Override
     public int getCount() {
      return name.size();
     }

     @Override
     public Object getItem(int position) {
      return null;
     }

     @Override
     public long getItemId(int position) {
      return 0;
     }

     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
      Holder holder;
      if (convertView == null) {
       holder = new Holder();
       convertView = inflater.inflate(R.layout.list_item, null);
       holder.txtName = (TextView) convertView.findViewById(R.id.name);
       holder.txtAddress = (TextView) convertView
         .findViewById(R.id.address);
       holder.txtQua = (TextView) convertView.findViewById(R.id.quali);
       convertView.setTag(holder);
      } else {
       holder = (Holder) convertView.getTag();
      }
      holder.txtName.setText(Html.fromHtml("" + name.get(position)));
      holder.txtAddress.setText(Html.fromHtml("<b>Address : </b>"
        + address.get(position)));
      holder.txtQua.setText(Html.fromHtml("<b>Qualification : </b>"
        + qua.get(position)));

      return convertView;
     }

     private class Holder {
      TextView txtName, txtAddress, txtQua;
     }
    }

ParsingClass:-


package offlinereaddata.amit.com;

import java.util.ArrayList;
import java.util.jar.Attributes;

import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ParsingClass extends DefaultHandler {

     ArrayList<String> name = new ArrayList<String>();
     ArrayList<String> address = new ArrayList<String>();
     ArrayList<String> qua = new ArrayList<String>();

     public void startElement(String uri, String localName, String qName,
       Attributes attributes) throws SAXException {
      super.startElement(uri, localName, qName, (org.xml.sax.Attributes) attributes);
      if (localName.equalsIgnoreCase("name")) {
       tempStore = "";
      } else if (localName.equalsIgnoreCase("address")) {
       tempStore = "";
      } else if (localName.equalsIgnoreCase("qua")) {
       tempStore = "";
      }else{
       tempStore = "";
      }
     }

     @Override
     public void endElement(String uri, String localName, String qName)
       throws SAXException {
      super.endElement(uri, localName, qName);
      if (localName.equalsIgnoreCase("name")) {
       name.add(tempStore);
      } else if (localName.equalsIgnoreCase("address")) {
       address.add(tempStore);
      } else if (localName.equalsIgnoreCase("qua")) {
       qua.add(tempStore);
      }
      tempStore = "";
     }

     private String tempStore = "";

     @Override
     public void characters(char[] ch, int start, int length)
       throws SAXException {
      super.characters(ch, start, length);
      tempStore += new String(ch, start, length);
     }
    }


Thanks Friends

This is very use full for you this is easy to understand ........

Thursday, May 8, 2014

Sqlite Data Base Insert, Update ,Remove Android Sqlite Data base

If you implement this code to manage simple app this will make you helpful .......

User Interfaces are as:-
1:-


<?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">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView1" android:text="Employee App"
android:layout_gravity="center"></TextView>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/txtEname"
android:hint="Enter Employee Name">
<requestFocus></requestFocus>
</EditText>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/txtDesig"
android:hint="Enter Designation"></EditText>
<EditText android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/txtSalary"
android:hint="Enter Salary"></EditText>
<LinearLayout android:layout_height="wrap_content"
android:id="@+id/linearLayout1" android:layout_width="match_parent">
<Button android:id="@+id/btnAdd" android:text="Add Employee"
android:layout_height="wrap_content" android:layout_width="wrap_content"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/btnUpdate"
android:text="Update Record"></Button>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/btnDelete"
android:text="Delete "></Button>
</LinearLayout>
<ListView android:layout_width="match_parent"
android:layout_height="match_parent" android:id="@+id/lvEmployees"></ListView>
</LinearLayout>


2:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentLeft="true"
android:id="@+id/lblEname"></TextView>
<TextView android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentTop="true" android:layout_alignParentRight="true"
android:id="@+id/lblSalary"></TextView>
<TextView android:text="TextView" android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content" android:id="@+id/lblDesignation"
android:layout_width="wrap_content" android:layout_below="@+id/lblSalary"
android:layout_alignParentLeft="true"></TextView>

</RelativeLayout>


Manifest:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.vrs.employeeapp"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".EmployeeAppActivity"
                  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>

MainActivity:-

package com.vrs.employeeapp;

/***
 *    Application Name : MessageBox 
 *    Author : Vimal Rughani
 *    Website : http://pulse7.net
 *    For more details visit http://pulse7.net/android/sqlite-database-android/
 */

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class EmployeeAppActivity extends Activity implements OnClickListener {

// Primitive Variables
String selected_ID = "";

// Widget GUI Declare
EditText txtEname, txtDesig, txtSalary;
Button btnAddEmployee, btnUpdate, btnDelete;
ListView lvEmployees;

// DB Objects
DBHelper helper;
SQLiteDatabase db;

// Adapter Object
SimpleCursorAdapter adapter;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Init DB Objects
helper = new DBHelper(this);

// Widget GUI Init
txtEname = (EditText) findViewById(R.id.txtEname);
txtDesig = (EditText) findViewById(R.id.txtDesig);
txtSalary = (EditText) findViewById(R.id.txtSalary);
lvEmployees = (ListView) findViewById(R.id.lvEmployees);

btnAddEmployee = (Button) findViewById(R.id.btnAdd);
btnUpdate = (Button) findViewById(R.id.btnUpdate);
btnDelete = (Button) findViewById(R.id.btnDelete);

// Attached Listener
btnAddEmployee.setOnClickListener(this);
btnUpdate.setOnClickListener(this);
btnDelete.setOnClickListener(this);
lvEmployees.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> adapter, View v,
int position, long id) {

String name, desig, salary;

// Display Selected Row of Listview into EditText widget

Cursor row = (Cursor) adapter.getItemAtPosition(position);
selected_ID = row.getString(0);
name = row.getString(1);
desig = row.getString(2);
salary = row.getString(3);

txtEname.setText(name);
txtDesig.setText(desig);
txtSalary.setText(salary);
}
});

// Fetch Data from database
fetchData();
}

@Override
public void onClick(View v) {

// Perform CRUD Operation

if (v == btnAddEmployee) {

// Add Record with help of ContentValues and DBHelper class object
ContentValues values = new ContentValues();
values.put(DBHelper.C_ENAME, txtEname.getText().toString());
values.put(DBHelper.C_DESIGNATION, txtDesig.getText().toString());
values.put(DBHelper.C_SALARY, txtSalary.getText().toString());

// Call insert method of SQLiteDatabase Class and close after
// performing task
db = helper.getWritableDatabase();
db.insert(DBHelper.TABLE, null, values);
db.close();

clearFields();
Toast.makeText(this, "Employee Added Successfully",
Toast.LENGTH_LONG).show();

// Fetch Data from database and display into listview
fetchData();

}
if (v == btnUpdate) {

// Update Record with help of ContentValues and DBHelper class
// object

ContentValues values = new ContentValues();
values.put(DBHelper.C_ENAME, txtEname.getText().toString());
values.put(DBHelper.C_DESIGNATION, txtDesig.getText().toString());
values.put(DBHelper.C_SALARY, txtSalary.getText().toString());

// Call update method of SQLiteDatabase Class and close after
// performing task
db = helper.getWritableDatabase();
db.update(DBHelper.TABLE, values, DBHelper.C_ID + "=?",
new String[] { selected_ID });
db.close();

// Fetch Data from database and display into listview
fetchData();
Toast.makeText(this, "Record Updated Successfully",
Toast.LENGTH_LONG).show();
clearFields();

}
if (v == btnDelete) {

// Call delete method of SQLiteDatabase Class to delete record and
// close after performing task
db = helper.getWritableDatabase();
db.delete(DBHelper.TABLE, DBHelper.C_ID + "=?",
new String[] { selected_ID });
db.close();

// Fetch Data from database and display into listview
fetchData();
Toast.makeText(this, "Record Deleted Successfully",
Toast.LENGTH_LONG).show();
clearFields();

}

}

// Clear Fields
private void clearFields() {
txtEname.setText("");
txtDesig.setText("");
txtSalary.setText("");
}

// Fetch Fresh data from database and display into listview
private void fetchData() {
db = helper.getReadableDatabase();
Cursor c = db.query(DBHelper.TABLE, null, null, null, null, null, null);
adapter = new SimpleCursorAdapter(
this,
R.layout.row,
c,
new String[] { DBHelper.C_ENAME, DBHelper.C_SALARY,
DBHelper.C_DESIGNATION },
new int[] { R.id.lblEname, R.id.lblSalary, R.id.lblDesignation });
lvEmployees.setAdapter(adapter);
}
}




SQLiteOpenHelper Class Extends:- 

package com.vrs.employeeapp;

/***
 *    Application Name : MessageBox 
 *    Author : Vimal Rughani
 *    Website : http://pulse7.net
 *    For more details visit http://pulse7.net/android/sqlite-database-android/
 */


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper {

// Static Final Variable database meta information

static final String DATABASE = "empapp.db";
static final int VERSION = 1;
static final String TABLE = "emp";

static final String C_ID = "_id";
static final String C_ENAME = "ename";
static final String C_DESIGNATION = "designation";
static final String C_SALARY = "salary";

// Override constructor
public DBHelper(Context context) {
super(context, DATABASE, null, VERSION);

}

// Override onCreate method
@Override
public void onCreate(SQLiteDatabase db) {

// Create Employee table with following fields
// _ID, ENAME, DESIGNATION and SALARY
db.execSQL("CREATE TABLE " + TABLE + " ( " + C_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + C_ENAME + " text, "
+ C_DESIGNATION + " text, " + C_SALARY + " text )");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

// Drop old version table
db.execSQL("Drop table " + TABLE);

// Create New Version table
onCreate(db);
}

}



Supportive 


package com.vrs.employeeapp;

public interface OnItemClickListener extends
android.widget.AdapterView.OnItemClickListener {

}


Thanks to All My Friends