Sample Code for ListView with SQLite Database Connection in Android

Sample Code for ListView with SQLite Database Connection in Android

Here We are going to discuss 4 important features in android from development prospective with sample code and example.1. How to use ListView in android with example.

2. How to connect to SQLite database in android with example.
3. How to fetch contacts in android.
4. Finally practical use of how to fetch contacts from Contacts database(SQLite Database)and show in Listview in android.
 There are so many ways to populate the ListView items in android,we can use ArrayAdapter, BaseAdapter etc for this purpose.

In this Post we will discuss how to fetch contacts from contacts database (SQLite Database)and populate ListView items with these contacts.
Here I have created an App which shows the List of Phone Book Contact Names in a listview in Andrid.
Refer the below activity, which contains a Listview and the Listview contains items from phone contacts list. We will explain details in below section.


The above Activity is called PhoneBookActivity in our code. Which shows contacts items in a  listview. Also You will find 2 xml files associated with this application.

1. phone_book.xml       which contains a ListView item
2. each_contact.xml     which contains  a TextView item inside a listview to show the the Contact Names for each item.

Since we reading the contact names so do not forget to include the following permission in the Manifest  file of your project: Add the below line in your Manifest xlm file before the code for lunching your activity.
<uses-permission android:name=”android.permission.READ_CONTACTS”/>

Now coming to the xml layout. Add this 2 xlm files in your project

 XML Layouts:

 1. phone_book.xml 

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=””



2. each_contact.xml

Leave a Reply

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