2017-10-11 157 views
0

我对如何notifyDataSetChanged()作品在BaseExpandableListAdapternotifyDataSetChanged如何工作?

我更新一个布尔变量的一个问题,它的输出决定了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; 
     } 
    } 
+0

您的适配器没有数据更改。请在数据适配器内提供“allCommentsVisiable”值。 –

+0

目前它是一个私人memeber变量的“公共类PostListAdapter扩展BaseExpandableListAdapter” –

+0

其他成员:私人列表 postList; 私人上下文上下文; private String SessionID; –

回答

0

notifyDataSetChanged

通知所附的观察者的基础数据已 改变任何视图反映了数据集应刷新本身。 Reference

而在你的情况下,没有任何潜在的数据变化。为了使它工作,你需要改变你的清单postList项目,所以它会更新设置和计数器将随着设置的大小更新。

相关问题