2015-11-03 64 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; 
} 
}