Example usage for android.widget ExpandableListAdapter getChildView

List of usage examples for android.widget ExpandableListAdapter getChildView

Introduction

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

Prototype

View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
        ViewGroup parent);

Source Link

Document

Gets a View that displays the data for the given child within the given 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();
            }/*www.jav  a 2 s  .co  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();
}