Showing recursive lists inside a tab view
Algorithm question here.
I'm creating an app that shows a legal document, with tabs for navigation (TOC, bookmarks, etc). Inside the TOC tab, I need to show a multilevel table of contents. At the 'leaf' of the toc, I need to show a TextView
So, I could have:
tab1: List -> List -> List -> List -> List -> TextView
or
tab1: List -> List -> List -> TextView
or
tab1: List -> TextView
depending on the chapter, section, subsection, subsubsection structure of the book I'm showing.
Now, it doesn't matter how deep you are, the TabHost needs to be ALWAYS PRESENT, to provide the main navigati开发者_Go百科on. (Yes, I asked, and I need to use the tabs, not a menu.)
The question:
How do you implement the recursive List inside the FrameLayout of a tab? Or should I use a ListView styled as tabs and just not use the TabHost?
Ideas?
Thanks!
llappallOkay. Number one you cannot put ListViews
inside ListViews
, ScrollViews
, GridViews
or anything scrollable for that matter (i.e. a ListView
item cannot be ListView
). It might compile, it might run, but the results will not be what you expect or want. This is because a ListView
cannot have a height which is set to WRAP_CONTENT
.
You can have a two-level list (ExpandableListView
) but if you require more levels than that you will have to implement the functionality yourself by extending ListView
or ExpandableListView
.
You can also have sectioned lists, and lists with multiple item types, but there is no way using the default SDK components to get a 5-level list.
Number two: Yes you can have a ListView
inside a TabHost
. You won't be able to use a ListActivity
, but that just means you'll have to call the ListView
methods directly:
ListView myList = findViewById(R.id.myList);
myList.setAdapter(myListAdapter);
instead of calling the inbuilt ListActivity
methods.
Just place your ListView
inside the FrameLayout
in your layout file. If you have three tabs and the ListView
is the first element inside the FrameLayout
, then it will be displayed as the content for the first tab. If it is the second element, it will be the content for second tab and so on.
The only way you could implement a recursive list with inbuilt components would be to use a single ListView
, and then change the contents of the adapter of the ListView
when a user selects an item (essentially a drill-down menu using a single ListView). You'd also need to catch the back button with onBackPressed
in order to allow the user to navigate back up the list, or provide a back button somewhere.
精彩评论