2017-10-11 158 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項目,所以它會更新設置和計數器將隨着設置的大小更新。

相關問題