Introduction
Before creating an app in Android Studio, I will explain in brief about the SQLite database. SQLiteDatabase is the base class for working with an SQLite database in Android, which provides some methods to open, query, update and close the database.
Open Android Studio and start a new Android Studio project

Then enter the application name and select path for it.

Select Minimum SDK for Phone and Tablet option,

Click Next and select Blank Activity,

Click Next and by default, a blank activity with name MainActivity will be displayed,


By default, Hello world will be displayed and the application will look like this with MainActivity.

In activity_mail.xml, add TextView control.
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/textView"
- android:layout_centerHorizontal="true"
- android:textSize="30dp"
- android:text="CRUD for Student using SQLLite"
- />
Add a java class called DBHelper.java to create a database.

Extend this DBHelper.java class with SQLLiteOpenHelper class. Create a subclass of the SQLLiteOpenHelper class. This class provides the getReadableDatabase() and getWriteableDatabase() methods to get access to an SQLLiteDatabase object.
- package com.test.ppandey.contactapp;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.DatabaseUtils;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import java.util.ArrayList;
- import java.util.HashMap;
- /**
- * Created by ppandey on 12/15/2015.
- */
- public class DBHelper extends SQLiteOpenHelper {
- public static final String DATABASE_NAME = "contactdb.sqlite";
- public static final String CONTACTS_TABLE_NAME = "mycontacts";
- public static final String CONTACTS_COLUMN_ID = "id";
- public static final String CONTACTS_COLUMN_STUNAME = "name";
- public static final String CONTACTS_COLUMN_STUPHONE = "phone";
- public static final String CONTACTS_COLUMN_STUSTREET = "street";
- public static final String CONTACTS_COLUMN_STUEMAIL = "email";
- public static final String CONTACTS_COLUMN_STUCITY = "place";
- private HashMap hp;
- public DBHelper(Context context)
- {
- super(context, DATABASE_NAME , null, 3);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(
- "create table mycontacts " +
- "(id integer primary key autoincrement, name text,phone text,email text, street text,place text)"
- );
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- db.execSQL("DROP TABLE IF EXISTS mycontacts");
- onCreate(db);
- }
- public boolean addStudentContact(String contactname,String contactphone,String contactstreet,String contactemail, String contactplace){
- /*,*/
- SQLiteDatabase db=this.getWritableDatabase();
- ContentValues contantValues = new ContentValues();
- contantValues.put("name",contactname);
- contantValues.put("phone", contactphone);
- contantValues.put("street",contactstreet);
- contantValues.put("email",contactemail);
- contantValues.put("place",contactplace);
- db.insert("mycontacts", null, contantValues);
- db.close();
- return true;
- }
- public boolean updateStudentContact(Integer contactid,String contactname,String contactphone,String contactstreet,String contactemail, String contactplace)
- {
- /*,String contactname,*/
- SQLiteDatabase db=this.getWritableDatabase();
- ContentValues contantValues = new ContentValues();
- contantValues.put("name",contactname);
- contantValues.put("phone", contactphone);
- contantValues.put("street",contactstreet);
- contantValues.put("email",contactemail);
- contantValues.put("place",contactplace);
- db.update("mycontacts", contantValues, "id = ?", new String[]{Integer.toString(contactid)});
- db.close();
- return true;
- }
- public Integer deleteContact(Integer id){
- SQLiteDatabase db=this.getWritableDatabase();
- return db.delete("mycontacts","id = ?",new String[]{Integer.toString(id)});
- }
- public Cursor getData(int contactid){
- SQLiteDatabase db=this.getWritableDatabase();
- Cursor res=db.rawQuery("Select * from mycontacts where id = " + contactid + "", null);
- return res;
- }
- public int numberOfRows(){
- SQLiteDatabase db=this.getWritableDatabase();
- int numRows=(int) DatabaseUtils.queryNumEntries(db,CONTACTS_TABLE_NAME);
- return numRows;
- }
- public ArrayList<String> getAllStudentContacts(){
- ArrayList<String> arraylist= new ArrayList<String>();
- SQLiteDatabase db=this.getReadableDatabase();
- Cursor cursor=db.rawQuery("Select * from mycontacts",null);
- if (cursor.moveToFirst()) {
- do {
- arraylist.add(cursor.getString(cursor.getColumnIndex(CONTACTS_COLUMN_STUNAME)));
- } while (cursor.moveToNext());
- }
- return arraylist;
- }
- }
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/scrollView1"
- >
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="350dp"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- tools:context="com.test.ppandey.contactapp.DisplayContact">
- <EditText
- android:id="@+id/editTextName"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_marginTop="5dp"
- android:layout_marginLeft="82dp"
- android:ems="10"
- android:inputType="text" >
- </EditText>
- <EditText
- android:id="@+id/editTextEmail"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/editTextStreet"
- android:layout_below="@+id/editTextStreet"
- android:layout_marginTop="22dp"
- android:ems="10"
- android:inputType="textEmailAddress" />
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/editTextName"
- android:layout_alignParentLeft="true"
- android:text="@string/name"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/editTextCity"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="28dp"
- android:onClick="saveData"
- android:text="@string/save" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/editTextEmail"
- android:layout_alignLeft="@+id/textView1"
- android:text="@string/email"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <TextView
- android:id="@+id/textView5"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBottom="@+id/editTextPhone"
- android:layout_alignLeft="@+id/textView1"
- android:text="@string/phone"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <TextView
- android:id="@+id/textView4"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_above="@+id/editTextEmail"
- android:layout_alignLeft="@+id/textView5"
- android:text="@string/street"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <EditText
- android:id="@+id/editTextCity"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignRight="@+id/editTextName"
- android:layout_below="@+id/editTextEmail"
- android:layout_marginTop="30dp"
- android:ems="10"
- android:inputType="text" />
- <TextView
- android:id="@+id/textView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/editTextCity"
- android:layout_alignBottom="@+id/editTextCity"
- android:layout_alignParentLeft="true"
- android:layout_toLeftOf="@+id/editTextEmail"
- android:text="@string/country"
- android:textAppearance="?android:attr/textAppearanceMedium" />
- <EditText
- android:id="@+id/editTextStreet"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/editTextName"
- android:layout_below="@+id/editTextPhone"
- android:ems="10"
- android:inputType="text" >
- <requestFocus />
- </EditText>
- <EditText
- android:id="@+id/editTextPhone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/editTextStreet"
- android:layout_below="@+id/editTextName"
- android:ems="10"
- android:inputType="phone|text" />
- </RelativeLayout>
- </ScrollView>









Fernanda GutembergPosted Nov 16, 2021, 5:20 PM
Great job, could develop a CRUD using FLUTTER in Android Studio, thanks
AJAY donorPosted Dec 30, 2015, 6:53 AM
Please Lat,s me soon as possible
AJAY donorPosted Dec 30, 2015, 6:52 AM
Hi Pradip I am .net beground I want learn Android with mvc .net. so how to start learn.
Joe WilsonPosted Dec 26, 2015, 2:15 PM
Well, it was great.
Santhakumar MunuswamyPosted Dec 22, 2015, 10:50 AM
Good work. keep it up
Atul RawatPosted Dec 21, 2015, 8:29 AM
nice article sir
Ish BandhuPosted Dec 20, 2015, 11:27 PM
Excelent Work
Harshad PansuriyaPosted Dec 19, 2015, 7:30 AM
Nice one .can you post the CRUD App using Web Server not any DataBase I Really need that Concept...????
Humayun Kabir MamunPosted Dec 18, 2015, 4:48 AM
Nice...
Ankur MistryPosted Dec 18, 2015, 12:52 AM
excellent work
Manish DwivediPosted Dec 17, 2015, 11:36 PM
Nice Article