Friday, March 5, 2010

Expandable list with CWAC

I received a comment at the expandable list adapter post that I should take a look at the CommonsWare Android Components (CWAC) project. CWAC aims to provide off-the-shelf components for Android programmers which is a very interesting proposition. In particular, the EndlessAdapter does pretty much the same as my example program at the post, except that the CWAC component offers a nice API to programmers while my program is nothing more than an example from which parts can be copied into somebody else's code.

Click here to download the example program.

Still, I think it is interesting to share my experience with CWAC EndlessAdapter because I reimplemented my example program using the EndlessAdapter. The largest - and, IMHO, most annoying - difference is that EndlessAdapter does the caching from the slow data source and the updating of the list in two separate stages. This means that if an application decides to cache more than one item, those items will not appear in the list until all the items of the particular batch were loaded. If you execute the example program, you will see batches of 5 items appearing (because the code preloads 5 items at once). EndlessAdapter really leaves only one other option open: that only one item is cached. This is less user-friendly, however, because the user has to wait for each item when the list is scrolled down. So I think the component should definitely support list update while a larger batch of items is being fetched from the data source. This would require change of the component API.

The other difference is more like a matter of taste. Personally, I found combining the loading and real data widget into the same row layout and fiddling with the visibility hard to maintain. My test program used a separate row layout for the loading widget which is easier to maintain but is less efficient.

Anyway, my goal with this post was to advertise the CWAC project because I believe that the Android component market is an important. one. That's true even if Android's component support could be better.

3 comments:

big panel said...

How to do an expandable list where the indicator arrow to expand the list is hidden if there's no child

In my project I also need to expand when ones click on the arrow (if exits) but call an another activty when ones click on the title of the Item

0


I've created my own expander_group.xml
with

item
android:state_expanded="true"
android:state_empty="true"
android:drawable="@drawable/empty"


and set it up in my ExpandableListActivity

Drawable icon = this.getResources().getDrawable(R.drawable.expande r_group);
getExpandableListView().setGroupIndicator(icon);

Icon are loaded but no empty icon in front of empty group till I tried to expand it. When I click on it it actually disapear as it should be


Someone told me about BaseAdapter and writing all the views by hand

What is the best way to acheive that : no icon for empty groups and
title of the group clickable


You code is a very different approch. Can't you show me how can i acheive that in your way

thanx a lot

Gabor Paller said...

Big panel, have you checked the example program at this blog entry?

kenna said...

Dear Gabor, maybe you gave a wrong link? I found your article in
http://mylifewithandroid.blogspot.com/2011/06/hiding-group-indicator-for-empty-groups.html
Thank you!