Android Custom List View
Post
Cancel

Custom List View

A - Introduction

ListView is a very important control in Android programming. Almost every apps has ListView.

ListView doesn’t only contain text but also other controls like ImageView, Button, Checkbox…

This post will show you how to customize a ListView.

B - Step by step demo

First of all, we must add a ListView into main layout (main.xml file)

Next, create a list_item.xml file - this file will define all the components, controls of EACH ITEM in ListView.

 

Create a SongInfo class to define all the information of a song object like song, singer, isCheck, rate:

Now, it’s time to play with Custom List View :byebye:

Create new  ListItem class that extends the LinearLayout super class.

This class will declare all the components and controls in  list_item.xml file:

Custom List View

Create new ListAdapter class extends ArrayAdapter<SongInfo> super class:

Custom List View

Override the getView method to assign values of SongInfo to the appropriate components, controls in a ListView item.

Custom List View

In the ListViewDemoActivity class, onCreate() method, we need to init and push some dummy data to  ListAdapter, after that setAdapter for ListView:

Custom List View

Done! :adore:

Enjoy!:beauty:

C - Download Source Code Custom List View

http://www.mediafire.com/download.php?ktzucwzunnndbsh

This post is licensed under CC BY 4.0 by the author.