Question

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

Was it helpful?

Solution

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.

OTHER TIPS

In my opinion this is a better answer

I was trying to put an action bar below the last child of each group if needed, this works very nice for that. Since the action bar has nothing to do with my data, I couldn't use the same object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top