2011-04-12 55 views
3

我正在嘗試編寫多級樹。我確實看過expandablelistview,但它只支持兩個級別。我也看過其他問題(SO)&的帖子和我發現的最有希望的帖子是http://mylifewithandroid.blogspot.com/2011/02/3-level-expandable-lists.html多級別視圖:expandablelistview

據我所知,我將不得不寫一些自定義來處理多級樹。 什麼是最好的推薦方法? 我可以添加exapandablelistview作爲一個exapanablelistview的孩子?

感謝

+0

找到了一個類似的鏈接http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html#comment-form – jsp 2011-04-12 21:35:22

+1

也發現這個http://code.google.com/ p/tree-view-list-android/ – jsp 2011-04-13 20:31:24

+1

請參閱我的項目的鏈接,其中可以實現N級樹列表視圖.https://github.com/Jaldips/Android-MultilevelTreeListView – 2014-01-06 08:38:08

回答

1

可以實現N級ExpandableListView,如果你與你的自定義BaseExpandableListAdapter使用它。

在此擴展適配器,您覆蓋

public View getGroupView(int groupPosition, boolean isExpanded, 
    View convertView, ViewGroup parent) 

法,BaseExpandableListAdapter實例分配到convertView,並將其返回。

如果您已覆蓋適配器中的所有必要方法,則應該可以工作。

1

這是可能的,但它會使GUI結構太複雜,無法實現。

首先,您必須知道ExpandableListView呈現的物品由BaseExpandableListAdapter給出。您必須設計和實現與您的level-2項目相同數量的適配器,以便可以爲每個level-2項目正確渲染級別3列表。

我建議你重新設計GUI。多級ExpandableListView不僅使代碼複雜化,也可能弄亂屏幕。