一. 重写ExpandableListView
/**
*
* 自定义ExpandableListView 解决嵌套之下显示不全的问题
*/
public class CustomExpandableListView extends ExpandableListView {
public CustomExpandableListView(Context context) {
super(context);
}
public CustomExpandableListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CustomExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 解决显示不全的问题
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2
, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
二. 修改ListViewAdapter
-
getChildrenCount()
返回1
-
getChildView()
返回的是ExpandableListView
对象。
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
CustomExpandableListView eListView = getExpandableListView();
List<Item> childData = new ArrayList<Item>();
childData.addAll(getChildData(groupPosition));
// 嵌套第三层的适配器
PackageChildListAdapter packageChildListAdapter = new PackageChildListAdapter(mContext, childData);
eListView.setAdapter(packageChildListAdapter);
return eListView;
}