Android SQLite Insert Update Delete Display data example tutorial with source code download

How to perform various operations like Add, Edit, Delete, Update records on SQLite database in android app via User.

SQLite database is one of the most common way to store text based values in android applications, The values can be multiple type of like Text messages, Call logs, Social networking chatting applications user chats, Browser history, File logs, Error logs, User data. SQLite database is uniquely developed for gives us the ability to create local database inside our android application to store data locally and as we all know that if there is a database available then also there are the options available to create tables inside it. The method of creating database and tables is completely based upon queries and commands which we have pass in our android program. So here is the complete step by step tutorial for Android SQLite Insert Update Delete Display data example tutorial with source code download.

Brief review about this project : Inside this project we are performing various operations on SQLite database with multiple activity enviournment and every activity has is own task And as a developer I suggest you to download the whole project and import this project into Eclipse or Android studio and run it into Emulator, Enjoy .

android-project-download-code-button

About this project :

List of Activities inside this project :

  1. MainActivity.java .
  2. EditDataActivity.java .
  3. ListViewActivity.java .

List of Layout XML files inside this project :

  1. activity_main.xml .
  2. activity_edit_data.xml .
  3. activity_list_view.xml .
  4. listviewdatalayout.xml .

List of listAdapter classes java files :

  1. SQLiteHelper.java .
  2. SQLiteListAdapter.java .

Android SQLite Insert Update Delete Display data example tutorial source code starts from here .

Code for MainActivity.java file.

 package com.sqlitetutorial_android_examples.com;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

 EditText GetName,GetPhoneNumber,GetSubject ;
 Button Submit, EditData, DisplayData;
 SQLiteDatabase SQLITEDATABASE;
 String Name, PhoneNumber, Subject ;
 Boolean CheckEditTextEmpty ;
 String SQLiteQuery ;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 GetName = (EditText)findViewById(R.id.editText1);
 
 GetPhoneNumber = (EditText)findViewById(R.id.editText2);
 
 GetSubject = (EditText)findViewById(R.id.editText3);
 
 Submit = (Button)findViewById(R.id.button1);
 
 EditData = (Button)findViewById(R.id.button2);
 
 DisplayData = (Button)findViewById(R.id.button3);
 
 Submit.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 DBCreate();
 
 SubmitData2SQLiteDB();
 
 }
 });
 
 EditData.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 Intent intent = new Intent(MainActivity.this, EditDataActivity.class);
 startActivity(intent);
 
 }
 });
 
 DisplayData.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 Intent intent = new Intent(MainActivity.this, ListViewActivity.class);
 startActivity(intent);
 
 }
 });
 }
 
 public void DBCreate(){
 
 SQLITEDATABASE = openOrCreateDatabase("DemoDataBase", Context.MODE_PRIVATE, null);
 
 SQLITEDATABASE.execSQL("CREATE TABLE IF NOT EXISTS demoTable(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR, phone_number VARCHAR, subject VARCHAR);");
 }
 
 public void SubmitData2SQLiteDB(){
 
 Name = GetName.getText().toString();
 
 PhoneNumber = GetPhoneNumber.getText().toString();
 
 Subject = GetSubject.getText().toString();
 
 CheckEditTextIsEmptyOrNot( Name,PhoneNumber, Subject);
 
 if(CheckEditTextEmpty == true)
 {
 
 SQLiteQuery = "INSERT INTO demoTable (name,phone_number,subject) VALUES('"+Name+"', '"+PhoneNumber+"', '"+Subject+"');";
 
 SQLITEDATABASE.execSQL(SQLiteQuery);
 
 Toast.makeText(MainActivity.this,"Data Submit Successfully", Toast.LENGTH_LONG).show(); 
 
 ClearEditTextAfterDoneTask();
 
 }
 else {
 
 Toast.makeText(MainActivity.this,"Please Fill All the Fields", Toast.LENGTH_LONG).show();
 }
 }
 
 public void CheckEditTextIsEmptyOrNot(String Name,String PhoneNumber, String subject ){
 
 if(TextUtils.isEmpty(Name) || TextUtils.isEmpty(PhoneNumber) || TextUtils.isEmpty(Subject)){
 
 CheckEditTextEmpty = false ;
 
 }
 else {
 CheckEditTextEmpty = true ;
 }
 }
 
 public void ClearEditTextAfterDoneTask(){
 
 GetName.getText().clear();
 GetPhoneNumber.getText().clear();
 GetSubject.getText().clear();
 
 }
 
}

Code for EditDataActivity.java file.

package com.sqlitetutorial_android_examples.com;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class EditDataActivity extends Activity {

 Button nextbutton, previousbutton, updatebutton, deletebutton;
 
 EditText name, phoneNumber, SubJect;
 
 SQLiteDatabase SQLITEDATABASE, SQLITEDATABASE2 ;
 
 String GetSQliteQuery, UpdateRecordQuery, DeleteQuery ;
 
 Cursor cursor, cursorCheckDataIsEmptyOrNot ;
 
 TextView idtextview;
 
 Boolean CheckEditTextEmpty;
 
 String GetName,GetPhoneNumber,GetSubject ;
 
 int UserID ;
 
 String ConvertUserID ;
 
 SQLiteHelper SQLITEHELPER;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_edit_data);
 
 nextbutton = (Button)findViewById(R.id.button1);
 previousbutton = (Button)findViewById(R.id.button2);
 updatebutton = (Button)findViewById(R.id.button3);
 deletebutton = (Button)findViewById(R.id.button4);
 
 name = (EditText)findViewById(R.id.editText1);
 phoneNumber = (EditText)findViewById(R.id.editText2);
 SubJect = (EditText)findViewById(R.id.editText3);
 
 idtextview = (TextView)findViewById(R.id.textview1);
 
 GetSQliteQuery = "SELECT * FROM demoTable" ;
 
 SQLITEDATABASE = openOrCreateDatabase("DemoDataBase", Context.MODE_PRIVATE, null);
 
 cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
 
 cursor.moveToFirst();
 
 GetSQLiteDatabaseRecords();
 
 
 nextbutton.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 if (!cursor.isLast()){
 
 cursor.moveToNext();
 } 

 GetSQLiteDatabaseRecords();
 
 }
 });
 
 previousbutton.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 if (!cursor.isFirst()){
 
 cursor.moveToPrevious();
 }
 GetSQLiteDatabaseRecords();

 }
 });
 
 updatebutton.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 GetName = name.getText().toString();
 GetPhoneNumber = phoneNumber.getText().toString();
 GetSubject = SubJect.getText().toString();
 
 ConvertUserID = idtextview.getText().toString();
 
 UserID = Integer.parseInt(ConvertUserID);
 
 UpdateRecordQuery = "UPDATE demoTable SET name='" + GetName + "', phone_number='" + GetPhoneNumber + "', subject='" + GetSubject + "' WHERE id=" + UserID + ";";
 
 CheckEditTextIsEmptyOrNot( GetName,GetPhoneNumber, GetSubject);
 
 if (CheckEditTextEmpty == false) {
 
 SQLITEDATABASE.execSQL(UpdateRecordQuery);
 
 cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
 
 cursor.moveToPosition(UserID);
 
 Toast.makeText(EditDataActivity.this,"Data Updated Successfully", Toast.LENGTH_LONG).show();
 
 }else {
 
 Toast.makeText(EditDataActivity.this,"Please Fill All the Fields", Toast.LENGTH_LONG).show();
 
 }
 
 
 }
 });
 
 deletebutton.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 ConvertUserID = idtextview.getText().toString();
 
 UserID = Integer.parseInt(ConvertUserID);
 
 DeleteQuery = "DELETE FROM demoTable WHERE id=" + UserID + ";";
 
 SQLITEDATABASE.execSQL(DeleteQuery);
 
 Toast.makeText(EditDataActivity.this, "Record Deleted Successfully", Toast.LENGTH_LONG).show();
 
 cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
 
 }
 });
 }
 
 public void GetSQLiteDatabaseRecords(){

 idtextview.setText(cursor.getString(0));
 
 name.setText(cursor.getString(1).toString());
 
 phoneNumber.setText(cursor.getString(2).toString());
 
 SubJect.setText(cursor.getString(3).toString());
 }
 
 public void CheckEditTextIsEmptyOrNot(String Name,String PhoneNumber, String subject ){
 
 if(TextUtils.isEmpty(Name) || TextUtils.isEmpty(PhoneNumber) || TextUtils.isEmpty(subject)){
 
 CheckEditTextEmpty = true ;
 
 }
 else {
 CheckEditTextEmpty = false ;
 }
 }
 
}

Code for ListViewActivity.java file.

package com.sqlitetutorial_android_examples.com;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;

public class ListViewActivity extends Activity {
 
 SQLiteHelper SQLITEHELPER;
 SQLiteDatabase SQLITEDATABASE;
 Cursor cursor;
 SQLiteListAdapter ListAdapter ;

 ArrayList<String> ID_ArrayList = new ArrayList<String>();
 ArrayList<String> NAME_ArrayList = new ArrayList<String>();
 ArrayList<String> PHONE_NUMBER_ArrayList = new ArrayList<String>();
 ArrayList<String> SUBJECT_ArrayList = new ArrayList<String>();
 ListView LISTVIEW;

 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_list_view);

 LISTVIEW = (ListView) findViewById(R.id.listView1);

 SQLITEHELPER = new SQLiteHelper(this);
 
 }

 @Override
 protected void onResume() {

 ShowSQLiteDBdata() ;
 
 super.onResume();
 }

 private void ShowSQLiteDBdata() {
 
 SQLITEDATABASE = SQLITEHELPER.getWritableDatabase();
 
 cursor = SQLITEDATABASE.rawQuery("SELECT * FROM demoTable", null);

 ID_ArrayList.clear();
 NAME_ArrayList.clear();
 PHONE_NUMBER_ArrayList.clear();
 SUBJECT_ArrayList.clear();
 
 if (cursor.moveToFirst()) {
 do {
 ID_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_ID)));
 
 NAME_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Name)));
 
 PHONE_NUMBER_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_PhoneNumber)));
 
 SUBJECT_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Subject)));

 } while (cursor.moveToNext());
 }
 
 ListAdapter = new SQLiteListAdapter(ListViewActivity.this,
 
 ID_ArrayList,
 NAME_ArrayList,
 PHONE_NUMBER_ArrayList,
 SUBJECT_ArrayList 
 
 );
 
 LISTVIEW.setAdapter(ListAdapter);
 
 cursor.close();
 }
}

Code for SQLiteHelper.java file.

 package com.sqlitetutorial_android_examples.com;

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

public class SQLiteHelper extends SQLiteOpenHelper {
 
 static String DATABASE_NAME="DemoDataBase";
 
 public static final String KEY_ID="id";
 
 public static final String TABLE_NAME="demoTable";
 
 public static final String KEY_Name="name";
 
 public static final String KEY_PhoneNumber="phone_number";
 
 public static final String KEY_Subject="subject";
 
 public SQLiteHelper(Context context) {
 
 super(context, DATABASE_NAME, null, 1);
 
 }

 @Override
 public void onCreate(SQLiteDatabase database) {
 
 String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+" ("+KEY_ID+" INTEGER PRIMARY KEY, "+KEY_Name+" VARCHAR, "+KEY_PhoneNumber+" VARCHAR, "+KEY_Subject+" VARCHAR)";
 database.execSQL(CREATE_TABLE);

 }

 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
 db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
 onCreate(db);

 }

}

Code for SQLiteListAdapter.java file.

 package com.sqlitetutorial_android_examples.com;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SQLiteListAdapter extends BaseAdapter {
 
 Context context;
 ArrayList<String> userID;
 ArrayList<String> UserName;
 ArrayList<String> User_PhoneNumber;
 ArrayList<String> UserSubject ;
 

 public SQLiteListAdapter(
 Context context2,
 ArrayList<String> id,
 ArrayList<String> name,
 ArrayList<String> phone,
 ArrayList<String> subject
 ) 
 {
 
 this.context = context2;
 this.userID = id;
 this.UserName = name;
 this.User_PhoneNumber = phone;
 this.UserSubject = subject ;
 }

 public int getCount() {
 // TODO Auto-generated method stub
 return userID.size();
 }

 public Object getItem(int position) {
 // TODO Auto-generated method stub
 return null;
 }

 public long getItemId(int position) {
 // TODO Auto-generated method stub
 return 0;
 }

 public View getView(int position, View child, ViewGroup parent) {
 
 Holder holder;
 
 LayoutInflater layoutInflater;
 
 if (child == null) {
 layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 child = layoutInflater.inflate(R.layout.listviewdatalayout, null);
 
 holder = new Holder();
 
 holder.textviewid = (TextView) child.findViewById(R.id.textViewID);
 holder.textviewname = (TextView) child.findViewById(R.id.textViewNAME);
 holder.textviewphone_number = (TextView) child.findViewById(R.id.textViewPHONE_NUMBER);
 holder.textviewsubject = (TextView) child.findViewById(R.id.textViewSUBJECT);
 
 child.setTag(holder);
 
 } else {
 
 holder = (Holder) child.getTag();
 }
 holder.textviewid.setText(userID.get(position));
 holder.textviewname.setText(UserName.get(position));
 holder.textviewphone_number.setText(User_PhoneNumber.get(position));
 holder.textviewsubject.setText(UserSubject.get(position));

 return child;
 }

 public class Holder {
 TextView textviewid;
 TextView textviewname;
 TextView textviewphone_number;
 TextView textviewsubject;
 }

}

Code for activity_main.xml layout file.

 <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="com.sqlitetutorial_android_examples.com.MainActivity" >

 <EditText
 android:id="@+id/editText1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:ems="10"
 android:hint="Enter Name Here"
 android:gravity="center" />

 <EditText
 android:id="@+id/editText2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="20dp"
 android:ems="10"
 android:inputType="phone" 
 android:hint="Enter Phone Number Here"
 android:gravity="center" />

 <EditText
 android:id="@+id/editText3"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText2"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="20dp"
 android:ems="10" 
 android:hint="Enter Subject Here"
 android:gravity="center" />

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Click Here to Insert Data into SQLite Database" />

 <Button
 android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="16dp"
 android:text="Click Here to Edit Records ONE By ONE" />

 <Button
 android:id="@+id/button3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button2"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="16dp"
 android:text="Click Here to Show all data into ListView" />

</RelativeLayout>

Code for activity_edit_data.xml file.

 <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="com.sqlitetutorial_android_examples.com.EditDataActivity" >

 <TextView 
 android:id="@+id/textview1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:gravity="center"
 android:layout_centerHorizontal="true"
 android:text="Record Id = "
 android:textAppearance="?android:attr/textAppearanceLarge"/>
 
 <EditText
 android:id="@+id/editText1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textview1"
 android:layout_centerHorizontal="true"
 android:ems="10"
 android:hint="Name Show Here"
 android:gravity="center"
 android:layout_marginTop="20dp" />

 <EditText
 android:id="@+id/editText2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="20dp"
 android:ems="10"
 android:inputType="phone" 
 android:hint="Phone Number Show Here"
 android:gravity="center" />

 <EditText
 android:id="@+id/editText3"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/editText2"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="20dp"
 android:ems="10" 
 android:hint="Subject Show Here"
 android:gravity="center" />

 <Button
 android:id="@+id/button1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="Show Next Record" />

 <Button
 android:id="@+id/button2"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button1"
 android:layout_centerHorizontal="true"
 android:text="Show Previous Record" />

 <Button
 android:id="@+id/button3"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button2"
 android:layout_centerHorizontal="true"
 android:text="Update Existing Record" />

 <Button
 android:id="@+id/button4"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_below="@+id/button3"
 android:layout_centerHorizontal="true"
 android:text="Delete Existing Record" />

</RelativeLayout>

Code for activity_list_view.xml layout file.

 <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="com.sqlitetutorial_android_examples.com.ListViewActivity" >

 <ListView
 android:id="@+id/listView1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true" >
 </ListView>
 
</RelativeLayout>

Code for listviewdatalayout.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 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" >

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentTop="true"
 android:text="ID = "
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textViewID"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/textView1"
 android:layout_alignBottom="@+id/textView1"
 android:layout_toRightOf="@+id/textView1"
 android:text="UserID"
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/textView1"
 android:text="Name = "
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textViewNAME"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textViewID"
 android:layout_toRightOf="@+id/textView2"
 android:text="Name"
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textView3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/textView2"
 android:text="Phone Number = "
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textViewPHONE_NUMBER"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBottom="@+id/textView3"
 android:layout_toRightOf="@+id/textView3"
 android:text="phone number"
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textView4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_below="@+id/textView3"
 android:text="Subject = "
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

 <TextView
 android:id="@+id/textViewSUBJECT"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignBaseline="@+id/textView4"
 android:layout_alignBottom="@+id/textView4"
 android:layout_toRightOf="@+id/textView4"
 android:text="subject"
 android:textAppearance="?android:attr/textAppearanceMedium"
 android:textColor="#050505" />

</RelativeLayout>

Screenshots:

Android SQLite Insert Update Delete Display data example tutorial with source code download

sqlite-tutorial-2

Show Multiple data from SQLite database inside ListView in android

Click here to download Android SQLite Insert Update Delete Display data example tutorial with source code download project with source code.

35 Comments

  1. these lines of your code:
    database = dbHelper.getWritableDatabase();
    cursor = database.rawQuery(“SELECT * FROM”+” “+DatabaseHelper.TABLE_NAME,null);

    are giving these errors:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.webwerks.vehicledemousingsqlite/com.webwerks.vehicledemousingsqlite.ListViewActivity}: android.database.sqlite.SQLiteException: table vehicle already exists (code 1): , while compiling: CREATE TABLE vehicle ( _id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, color TEXT, type TEXT);

    • Shashank, execute the table create query with ” CREATE TABLE IF NOT EXISTS “. like i have write it : SQLITEDATABASE.execSQL(“CREATE TABLE IF NOT EXISTS demoTable(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR, phone_number VARCHAR, subject VARCHAR);

    • I found the solution …
      Just add
      “private static final int DATABASE_VERSION = 1;”
      below SQLiteHelper class

      uninstall the app in emulator or device and try again launching the app

  2. i have error on the unable resume activity listview

  3. How to Resolve this: java.lang.RuntimeException: Unable to resume activity {app.ninedotsmobility.com.employlistview/app.ninedotsmobility.com.employlistview.ListViewActivity}: android.database.sqlite.SQLiteException: near “EXIST”: syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXIST demoTable (id INTEGER PRIMARY KEY, name VARCHAR, phone_number VARCHAR, email VARCHAR)

  4. Athiban please read the above comment reply it will help you.

  5. what the function from cursorCheckDataIsEmptyOrNot and SQLDATABASE2???

  6. Whenever I click the Show All data in ListView it crashes. I dont know why. Im using the latest version of Android Studio. Please Help! If you need my Source Code Ill send it on your E-Mail. Please Help!

  7. can u explain here y it crush?plzz

  8. Dear Sir,
    I am require to develop classroom booking application for my school project. Thus, I would like to use then modify your projects(SQLite database program and Log in program). Will you be able to allow me to use your codes. I have downloaded this SQLite program but it crashes whenever I click on Show all view list data. Please help sir. thank you

  9. please help me

  10. tried this on kitkat 32bit and 64bit android
    still not working
    keeps crashing when I tried to view/edit data…
    insert data no problem

  11. How I can create “SQLiteHelper” java ?

    Does it depends on activities class

  12. why button show data into listview has stopped? pls give me an explaination. I already put onclick name

  13. i tried in kitkat also but it getting crash while clicking on show data

Leave a Reply

Your email address will not be published. Required fields are marked *