Prerequisite

If you not understand this lecture .how can Retrieve Data into android SQLite Database.You should also read my previous lectures Android how can add data into SQLite  and Contextual Action mode in android studio . After reading these lecture you will also able to create Database of your Application And  also retrieve data from database.

What is SQLite

SQLite is a embedded (RDBMS) Stand for Relation DataBase Management system.Most relation database such as ORACAL and SQL are example that are working independently and store the information.SQLite is referred to as embedded because it is provided in the form of a library that is linked into applications.The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private.There is no sever that are running in the background.All the Database function are perform internally.

Introduction

In this lecture well we describe how can create Database in android studio.And also describe what is SQLite.why we can use it.After Reading this lecture you will understand how can create Retrieve data from Database in android And i hope you will create Database of your application and also retrieve data from database after reading this serios.

Description of Retrieve data into Database

In this lecture we will describe how can retrieve data in android SQLite database.This is a second lecture of android SQLite series.In my previous lecture i have to show how can add data into database.If you not understand this lecture you will also see my previous post.All the information were saved in database.So we retrieve data such as contact name mobile number and email address from database. and we will show in a list view.First of all we create project in android studio.Every project contain two file first is java class file and second is layout XML file.And we open a layout.XML file and add a button when user click on a button open a new activity.In that activity you will see all the data that are retrieve from database.So this is a work that will done this section.please read this lecture carefully all the detail is provides step by step.For more about Retrieve data into android SQLite database please click on Retrieve data into android SQLite database.

Layout XML

Now we create a new Layout.

Step 1=<- create a new Layout name data_list_layout->Right click> the ->layout folder-> select ->New option-> and click ->layout resource folder->

Step3=Step2->WriteName->Ok.

Alt Tag android sqlite new layout

Different property that are used in layout.xml file  explain here

  • warp_content   warp_content means height and width similar to the text that are entered.
  • Match_parent   means height and width similar to parent.
  • Edit text              The Edit Text control allows a user to enter text into an application
  • Button                  When user click on a button store information into database and show message

And Write the following code data_List_layout. XML file

  •  Step 5=<- create a new name row_layout->Right click> the ->layout folder-> select ->New option-> and click>layout resource folder->
  •  Step6=Step5->WriteName->Ok
  • if you not understand this please read first step1
  • In this example we are going to create a simple UI that includes only (Text  view)  with Different attributes.And Write the following code into row_layout.XML file

Write the following code activity_main_layout. XML file

Now you may open the Graphical layout editor to preview the User Interface you created.

Step7=Create new class <-NewContactActivity ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in below. 

Alt Tag Android make new class

<-WriteName->Ok

Alt Tag android sqlite new class

And Write the following code NewContactActivity. java class

  • Step8=Create new class <-UserContract ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step9=Step8->WriteName->Ok
  • if you not understand this please read first step7
  • And Write the following code UserContract. java class

  • Step10=Create new class <-UserDbHandler ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step11=Step10->WriteName->Ok.
  • if you not understand this  please read step 7.

And Write the following code UserDbHandler. java class

  • Step12=Create new class <-ListDataAdpter ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step13=Step12->WriteName->Ok.
  • if you not understand this  please read step 7.
  • And Write the following code ListDataAdpter. java class

  • Step14=Create new class <-DataProvider ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step15=Step14->WriteName->Ok.
  • if you not understand this  please read step 7.
  • And Write the following code DataProvider. java class

  • Step16=Create new class <-DataListActivity ->Right click-> the ->package name ->select ->New option-> and click-> java class that will show in above. 
  •  Step17=Step16->WriteName->Ok.
  • if you not understand this  please read step 7.
  • And Write the following code DataListActivity. java class

And Write the following code MainActivity. java class

Run the Application

Alt Tag android sqlite view button

Run the application and if you click on a first button the a new activity will open in this activity consists of three Edit text  and a button .when user add information  and click on save button then all the information will saved in database.and if user click on second button then a new activity open and show all the information that are save in database.

Alt Tag android sqlite view data

 

Conclusion

In this lecture we learn about Android SqLite database how can view data from database.. I hope you will understand this lecture.Thank you for reading this lecture Hope you got the idea.

  • mehreen naeem

    i want delete button in row of the listview to delete the row………so can you help????