Loading...

Custom Android ListView Example

Normal or standard android ListView only displays a list of scrollable items and the list items are automatically inserted to the list using an Adapter. This simple list view only slows list of text. Sometime you need to display images and some more text in the ListView, for that android allows you to customize list view. In this tutorial, you will learn to make custom android ListView and show pictures in multiple lines with text. If you need more customization you can design your listview layout yourself.

To make custom android ListView you need to create two XML layout files. One layout for ListView and another layout to hold the raw items of ListView, it contains one ImageView and one TextView inside LinearLayout. You can add more views according to your need.

Android Example: How to Implement Custom ListView in Android


Create a new android project with project name Custom Android ListView Example and follow the following steps to implement custom ListView in android.

XML Layout File

Open your main XML layout file and add a listview with an id custom_listview_example. Main XML layout file will look like below.

res/layout/activity_main.xml

Again create a new XML layout file and add ImageView and TextView inside LinearLayout with attributes like id, padding, layout_gravity etc. Following is the complete content of custom_list_item_layout.xml file.

res/layout/custom_list_item_layout.xml

Java Activity File

Create a new java activity file called AndroidListAdapter.java and extend ArrayAdapter. Here you need to connect ListView layout and set pass strings to TextView and images to ImageView. FOllowing is the complete code of java activity file.

src/AndroidListAdapter.java

Open java main activity file and add strings and images for listview list items. Following is the complete code of java activity file.

src/ MainActivity.java

Android Example: How to Implement Custom ListView in Android

That’s all. Now run your Custom Android ListView Example application which will look like above screenshot. Here I have added images with list items; you can also make your own custom ListView.
UI 6810044551023727136
Home item