Example usage for android.widget ExpandableListAdapter getChildrenCount

List of usage examples for android.widget ExpandableListAdapter getChildrenCount

Introduction

In this page you can find the example usage for android.widget ExpandableListAdapter getChildrenCount.

Prototype

int getChildrenCount(int groupPosition);

Source Link

Document

Gets the number of children in a specified group.

Usage

From source file:com.example.igorklimov.popularmoviesdemo.fragments.DetailFragment.java

private void setListViewHeight(ExpandableListView listView, int group) {
    ExpandableListAdapter listAdapter = listView.getExpandableListAdapter();
    if (mDefaultHeight == 0)
        mDefaultHeight = listView.getHeight();
    int totalHeight = 0;

    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.EXACTLY);
    for (int i = 0; i < listAdapter.getGroupCount(); i++) {
        if (((listView.isGroupExpanded(i)) && (i != group))
                || ((!listView.isGroupExpanded(i)) && (i == group))) {
            for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
                View listItem = listAdapter.getChildView(i, j, false, null, listView);
                listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
                totalHeight += listItem.getMeasuredHeight();
            }/*from   ww w .  j  a  v  a2s.c  o  m*/
            totalHeight += mDefaultHeight;
        }
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    int height = totalHeight + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
    if (height < mDefaultHeight)
        height = mDefaultHeight;
    params.height = height;
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:com.fortysevendeg.swipelistview.ExpandableSwipeListViewTouchListener.java

/**
 * Adds new items when adapter is modified
 *//* ww w.j  a  v  a  2s.  c o m*/
public void resetItems() {
    ExpandableListAdapter adp = swipeListView.getExpandableListAdapter();
    if (adp != null) {
        int count = 0;
        for (int i = 0; i < adp.getGroupCount(); i++) {
            //Add the total children and the group itself.
            count += adp.getChildrenCount(i) + 1;
        }
        System.out.println("TOTAL COUNT: " + count);
        for (int i = opened.size(); i <= count; i++) {
            opened.add(false);
            openedRight.add(false);
            checked.add(false);
        }
    }
}