[英]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.