ExpandableListView 表示状態の取得

ExpandableListView getChildCount() と、getChildAt(position) は表示して
いる Expandable List の数と表示している指定行の View を返してくれる。
表示している指定行の View なので、当然 Group と Child は混在している。
View の id と予め割り当てた LinearLayout の id であるかチェックしないと
振り分けはできない。

int childCount = expandableListView.getChildCount();
for(int i=0; i < childCount ;i++){
   int id = expandableListView.getChildAt(i).getId();
   if (id==R.id.expand_group){
      // group View
   }else if(id==R.id.expand_child){
      // child View
   }
}


この処理を、ExpandableListView の ExpandableListView.OnGroupCollapseListener や、
ExpandableListView.OnGroupExpandListener
( つまり、ExpandableListView#setOnGroupCollapseListener
や、ExpandableListView#setOnGroupExpandListener で定義する、、、)

これらの中で読んでも、折りたたみを開く前、たたむ前の状態を取得することに
なってしまう。

ExpandableListAdapter の onGroupCollapsed(int groupPosition) や、
onGroupExpanded(int groupPosition)
でも前の状態を取得することになってしまう。
ExpandableListActivity でも同じ。

折りたたみを開いた後、閉じた後の状態を取得してUIの処理をしたければ、
Handler を使うしかないみたいである。

以下が部分的なサンプル

Handler handler = new Handler();
handler.postDelayed(new Runnable(){
   @Override
   public void run(){
      int childCount = getExpandableListView().getChildCount();
      for(int i=0;i < childCount;i++){
         int id = getExpandableListView().getChildAt(i).getId();
         if (id==R.id.expand_group){
            // group View
         }else if(id==R.id.expand_child){
            // child View
         }
      }
   }
},100);