另一个 ExpandableListView 问题中的 ExpandableListView

ExpandableListView inside another ExpandableListView issue

我正在尝试创建 2 级 expandableListView.I 可以获取数据并完美绑定到 UI 元素,但两个 child 之间的高度是固定的。 因为内部 ExpandableListView 就像在滚动视图中一样,我只看到一个项目。

*group1
 ^child1
   //data
 ^child2
   //data
*group2
 ^child1
  //data
^child2
 //dataa

我正在设置 child dynamically.i 的高度。e 使用以下方法设置 group1 和 group2 之间的高度:

ListAdapter listadp = lv_ancillaryservice.getAdapter();
       if (listadp != null) {
           int totalHeight = 0;
           for (int i = 0; i < listadp.getCount(); i++) {
               View listItem = listadp.getView(i, null, lv_ancillaryservice);
               listItem.measure(0, 0);
               totalHeight += listItem.getMeasuredHeight();
           }
           ViewGroup.LayoutParams params = lv_ancillaryservice.getLayoutParams();
           params.height = totalHeight + (lv_ancillaryservice.getDividerHeight() * (listadp.getCount() - 1));
           lv_ancillaryservice.setLayoutParams(params);
           lv_ancillaryservice.requestLayout();

我在上面使用是因为 usingwrap_content 不适用于列表视图。现在的问题是:

  1. 单击 group1 时,会显示 ^child1 和 ^child2,单击 child1 时,我有一个列表视图,但我看不到完整列表。(group2位置固定)
  2. 滚动不起作用。

我用这个 link https://github.com/PaoloRotolo/ExpandableHeightListView .

解决了这个问题
package com.rtt.reeferwatch.utilities;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ExpandableListView;

public class ExpandableHeightListView extends ExpandableListView {

boolean expanded = false;

public ExpandableHeightListView(Context context) {
    super(context);
}

public ExpandableHeightListView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ExpandableHeightListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public boolean isExpanded() {
    return expanded;
}


@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (isExpanded()) {
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);

        ViewGroup.LayoutParams params = getLayoutParams();
        params.height = getMeasuredHeight();
    } else {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}

public void setExpanded(boolean expanded) {
    this.expanded = expanded;
}
}