问题
I am trying to write multi level tree. I did look at expandablelistview, but it only supports two levels. I did look at other questions(SO) & posts and the most promising post i have found is http://mylifewithandroid.blogspot.com/2011/02/3-level-expandable-lists.html
I understand that i will have to write something custom to handle multiple level tree. What is the best recommended approach to take? Can i add an exapandablelistview as a child to an exapanablelistview??
Thanks
回答1:
You can achieve an n-level ExpandableListView
, if you use it with your custom BaseExpandableListAdapter
.
In this extended adapter, you override the
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
method, assign a BaseExpandableListAdapter instance to the convertView, and return it.
If you have override all the necessary methods in your adapter, this should work.
回答2:
It's possible, but it would make the GUI structure too complicated to implement.
First, you have to know that the items rendered of ExpandableListView
are given by a BaseExpandableListAdapter
. You have to design and implement the same number of adapters as your level-2 items, so that the level-3 lists can be rendered correctly for each level-2 item.
I would suggest you to redesign the GUI. Multilevel ExpandableListView
not only complicate the code, maybe also mess up the screen.
来源:https://stackoverflow.com/questions/5639090/multi-level-view-expandablelistview