2017-10-11 1 views
0

は私がBaseExpandableListAdapternotifyDataSetChangedはどのように機能しますか?

notifyDataSetChanged()作品が、私はブール変数を更新しています方法についての質問があり、その出力は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

現在、それは "public class PostListAdapter extends BaseExpandableListAdapter"のプライベートメンバ変数です –

+0

他のメンバー:プライベートリスト postList; プライベートコンテキストコンテキスト。 プライベートString SessionID; –

答えて

0

notifyDataSetChanged

基になるデータが を変更されたデータ・セットを反映する任意のビューが自分自身をリフレッシュする必要があることを添付オブザーバーに通知します。 Reference

また、お客様の場合、基本的なデータ変更はありません。それを動作させるには、あなたのリストpostListのアイテムを変更する必要がありますので、セットを更新し、カウンタはセットのサイズとともに更新されます。

関連する問題