• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Multiple List-Item Layouts in One ListView

Hi there,

I'm trying to write a ListActivity that displays heirarchical information in the following manner:

  • The first item in the list displays the current node in a tree of items.
  • The second item displays information about the parent of the current node (if any).
  • Every following item displays information about the children of the current item (if any).
I've worked out the logic for populating the ListView in such a manner, but I encounter problems when trying to assign each individual list item a different layout xml file. I need to do this because the first item should display much more complex information than any other list item (eg an image, video, etc), and the parent item should display differently than the children (though not necessarily more complex). The children list items will display only 'meta' information (a few TextViews).

Is this feasible, or should I simply put the information for the current item and parent item in a View separate from from the ListView?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones