Listview is very common and important in android most app use ListView  to display data in list most common example Contact, Messenger etc. In this post i explain you how to create simple and custom listview in android. This post is focus on beginners and for those who want to learn how to create a simple and custom listview in android.

Simple ListView in Android

This is a simple application in which i use default android layout for ListView. 

 

Creating New Project

1. Create new project in your Eclipse IDE / Android Studio and fill all the details File ⇒ New Project.

2. Open your main layout file inside res ⇒ layout ⇒ activity.xml. Now in this add listview.

3. Now open your activity.java file inside src ⇒ com.package.name ⇒ Activity.java and write code to populate listView with data.

In above code i create simple Array String and add that data to ArrayList after adding data to arraylist i use ArrayAdapter to add data to listview and also call default layout

And after that i set data to Adapter using setAdapter.

Custom ListView in Android

Creating New Project

1. Create new project in your Eclipse IDE / Android Studio and fill all the details File ⇒ New Project.

2. Open your main layout file inside res ⇒ layout ⇒ activity.xml. Now in this add listview.

3. Now create new xml layout file inside res ⇒ layout folder

this is the layout we pass in our listview.

4.  Now first create a Custom java class in which we extend ArrayAdapter and pass String  to listview. In this i also use LayoutInflater  to inflate my view in list.

5. Now open your Mainactivity.java and create a array string, and create object of class pass class object to setAdapter.

In above i also use setOnItemClickListener to get click list item and display toast.