views:

1355

answers:

1

I have created a custom ExpandableListAdapter and everything works properly. What I'd like to be able to do is in each of the groups add a different type of child to the end. I have tried adding 1 to the getChildrenCount() number and then testing isLastChild in the getChildView() method, but that doesn't seem to work.

If a group has three children what I have working looks like this:

Group
    NormalChild
    NormalChild
    NormalChild

But I'd really like something like this:

Group
    NormalChild
    NormalChild
    NormalChild
    AlternateChild

The idea being that the AlternateChild could be a link to more info about the group. Any Ideas?

EDIT: ListView has addFooterView() which will allow you to add a footer to a whole ListView... wonder how to add them to the ExpandableListView's children, or if it's even possible

+2  A: 

Perhaps you could try a slightly different approach.

Rather than trying to add an extra item to the ListView directly, maybe try adding an 'AlternateChild' object to the underlying data source using a 'isAlternateChild' flag (or subclassing NormalChild or creating an IChild interface that you extend with NormalChild and AlternateChild.

Then within getChildView you can check to see if the object being displayed within the view is normal or alternate and create or populate the appropriate View-type accordingly.

By adding your extra object to the underlying data/list directly you can let the ExtendedListView do its thing normally. As an added bonus this means you can make the AlternateChild data dynamic and easily make changes to the data displayed in the view by modifying the corresponding object.

Reto Meier
That's pretty much exactly what I did. Just felt like there should have been a better way.
fiXedd