Android Custom List View

Android Custom List View

In our last module we have discussed List View already. Here we are going to discuss about custom List View using Base Adapter. For Custom ListView we have to create Bean class, Adapter class And an Activity.

We have discussed ListView attributes in our last module so we need to do create layout here:

Bind this layout with your Activity as like I did at last.

Beans : JavaBeans are classes that encapsulate many objects into a single object. It contains constructor, Getter, Setter Methods. With the help of Setter and Getter method user can set and get data. It also have zero argument constructor. Check out below code for more details.

Base Adapter:  BaseAdapter which extends object and implements ListAdapter and Spinner Adapter. It can be used in ListView, GridView and Spinner. BaseAdapter is very generic adapter which allows you to do pretty much whatever you want . Its custom Adapter from which you can do whatever you want to do with grid and list, But you need to do some coding for it. Check below coding for Base Adapter.

Use below xml for the Adapter:

Now We have to do coding for activity, Firstly you have to define global variable for List View, After declaration we need fetch it from xml by unique id. Also declare Array List of Bean and Adapter class as like I did. Now Add data in Array List and bind it with Adapter. At final stage you have to bind ListView with Adapter. Now you can run your code.

So here is the output :

customListView