AleSpero / ExpandableCardView

Simple expandable CardView for Android.
Apache License 2.0
689 stars 88 forks source link

listview inside expandablecardview #28

Open Deeptimay opened 6 years ago

Deeptimay commented 6 years ago

listview inside expandablecardview is showing only one item then you have to scroll. only one item visible at a time. help.

Deeptimay commented 6 years ago

public static boolean setListViewHeightBasedOnItems(ListView listView) {

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter != null) {

        int numberOfItems = listAdapter.getCount();

        // Get total height of all items.
        int totalItemsHeight = 0;
        for (int itemPos = 0; itemPos < numberOfItems; itemPos++) {
            View item = listAdapter.getView(itemPos, null, listView);
            item.measure(0, 0);
            totalItemsHeight += item.getMeasuredHeight();
        }

        // Get total height of all item dividers.
        int totalDividersHeight = listView.getDividerHeight() *
                (numberOfItems - 1);

        // Set list height.
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        params.height = totalItemsHeight + totalDividersHeight;
        listView.setLayoutParams(params);
        listView.requestLayout();

        return true;

    } else {
        return false;
    }
}
Deeptimay commented 6 years ago

This code helped me though.