I want to ask a general question about the proper way to handle a list with a hierarchy. The way I am doing it now is by calling the same activity with a bundle to handle the next query so I can drill down into the list. I am wondering if there is a better way to deal with lists like mine. Should I use multiple activities? (don’t know the depth of the list) or just requery my data when a user selects a list item. The problem with this solution is remembering the list item that was selected and the back button on the phone. I am sure I am missing something obvious but I’m new to Android. Any help or suggestions would be greatly appreciated. So here is what I do now:
- Query the data and display the list in
MainActivitywith with the root items. - User clicks on one of the items, get the index of that item and call
MainActivitywith a bundle that contains the index of the item selected. - Query the data with the new item and display the new list in
MainActivity. - rinse and repeat…
Also my list is more then two levels deep so I thing the ExpandableListView is out.
One of the reasons why
ExpandableListViewsupports only two levels of in depth, is because its very hard to make n-level tree to be user-friendly. Just imagine the mass on user’s screen if he or she goes to 5th level.But, nevertheless, here is the approach I would take. I haven’t implemented it yet, but this should be doable.
Introduce “Navigation Bar” at the top (like Windows Explorer has, or some sites have):
Use `Expandable list to show current level and the next level.
ExpandbleListViewwith next levels.Her is an example:
User clicks on
Subitem 4and sees:This is not trivial to implement, but shouldn’t be too hard. This gives navigation inside one Activity and uses highly optimized
ExpandableListViewcontrol. You only need to implement custom adapter.