[英]How does notifyDataSetChanged work?
我有一個關於notifyDataSetChanged()
如何在BaseExpandableListAdapter
工作的BaseExpandableListAdapter
我正在更新一個布爾變量,該變量的輸出確定getChildrenCount()
的輸出,但是可見的注釋數在調用它時不會改變
碼:
buttonViewComments.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
allCommentsVisible = !allCommentsVisible;
notifyDataSetChanged();
}
});
getChildrenCount:
public int getChildrenCount(int groupPosition) {
if(allCommentsVisible || postList.get(groupPosition).commentListSize()<=3)
return postList.get(groupPosition).commentListSize();
else{
return 3;
}
}
notifyDataSetChanged
通知附加的觀察者基礎數據已更改,任何反映該數據集的視圖都應刷新自身。 參考
在您的情況下,沒有任何基礎數據更改。 為了使其工作,您需要更改列表postList
項目,以便它將更新集合,並且計數器將隨着集合的大小而更新。
您將從此鏈接中獲得一些有用的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.