2015-11-03 59 views
0

我试图创建2级的expandableListView.I可以获取数据并完美绑定到UI元素,但两个孩子之间的高度是固定的。 因为内部ExpandableListView就像在scrollview里面我只看到一个项目。ExpandableListView在另一个ExpandableListView问题

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

我使用下面的方法设置孩子的身高dynamically.i.e 1与组2之间的hieght:

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. 被点击1组时,^ child1和^的child2是shownup和child1点击时,我有一个列表视图,但我无法看到完整的列表(第2组的位置是固定的)。
  2. 滚动是没有工作的地方。

回答

0

我使用此链接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; 
} 
}