Fork me on GitHub

Custom ListView in Android

Posted on 19 August 2014
Under Blog
Tagged
Android
Custom ListView in Android | Jay Rambhia’s Blog

An application must have a good looking UI and to get that we implemented our own custom layout to the listview to show songs in a playlist. Android provides ListView and various adapters which can be attached to it. For our purpose, we are using ArrayAdapter.

So to customize the listview, we need to have a customized ArrayAdapter. We would create a layout that we want each of the entry to have. We would override

getView(int position, View convertView, ViewGroup parent)

method and set our custom view.

Creating the layout

We first created a rough layout that we seemed to like.


Class that extends ArrayAdapter

Here AudioObject is a class that we made to handle audio metadata and other utilities.

A bit about ListView

ListView doesn’t load all the views at once. It reuses already drawn views. If you scroll down, it would reuse the views and not create new ones. In the getView method, if convertView is null it means that android is creating a new view. Most of the time it is not null because it reuses the previously created views.

Create Custom ListView


A little more advanced version of it looks like this.

playlist

P.S. Working on UI can be hectic.

If you liked - Custom ListView in Android and found it helpful, please share it with your fellow developers.

comments powered by Disqus


If you have some feedback or questions regarding this post, please add comments. I'd be happy to get some feedback.



If you liked this post, then you should follow Jay on twitter too. He would be excited to know that you like his work.