2012-07-20 31 views
1

我是新來的android開發(一個iOS開發人員),我用我的列表視圖BaseExpandableListAdapter。我將另外2個組添加到列表中(除其他外),然後調用notifyDataSetChanged並出現2個新組,但顯示爲空。我已經將日誌語句放入了一些已實現的適配器方法中,我可以看出,這並不是問我添加的2個組的長度。動態添加組到列表視圖不反映後notifyDataSetChanged

下面是說明爲什麼這樣做一些日誌信息...

有2組 - getGroupCount()

有5名兒童組0 - getChildrenCount()

有組1中的1個兒童 - getChildrenCount()

notifyDataSetChanged();

有4組 - getGroupCount()

有4名兒童在組0 - getChildrenCount()

有6個孩子在第1組 - getChildrenCount(

。 ..不試圖詢問第2組和第3組有多少個孩子?

謝謝

+0

如果您發佈自定義適配器的代碼,這將有所幫助。 – Luksprog 2012-07-20 07:36:52

回答

0

默認情況下添加的組已摺疊,我只需要遍歷每個組並確保其已擴展。這是我的代碼來做到這一點。

public void expandAllGroups(MyActivity activity) 
{ 
    ExpandableListView list = (ExpandableListView) activity.findViewById(R.id.MyList); 
    for (int i = 0; i < activity.adapter.getGroupCount(); i++) 
    { 
     list.expandGroup(i); 
    } 
} 
相關問題