【发布时间】:2014-07-09 23:01:46
【问题描述】:
我已经成功掌握了在 Child 和 innerChild 行中具有自定义布局的两级 ExpandableListView。问题是第一级的组头显示得很好。由于第一级 ExpandableListView 的高度,第二级的行部分显示。 第一级 ExpandableListView 托管一个布局,此布局托管另一个 ExpandableListView,后者又托管一个自定义布局,该布局具有 tableRow 应动态填充数据。
我重温了位于http://harrane.blogspot.com/2013/04/three-level-expandablelistview.html 的教程,建议使用一个自定义的 ExpandableListView,它将在第一级 ExpandableListView 的 Adapter 中使用。
class CustomExpandableListView extends ExpandableListView {
public CustomExpandableListView(Context context) {
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
/*
* Adjust height
*/
heightMeasureSpec = MeasureSpec.makeMeasureSpec(500, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
但是当我替换第一级 ExpandableListView 的行时,我在尝试扩展第一级 ExpandableListView 时遇到了 ClassCastException。
这是在一级Epandable列表视图中不使用CustomExpandableListview类时的代码:
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ExpandableListView elv = (ExpandableListView)
v.findViewById(R.id.eLV_bols_details_goods_list_item);
ExpandableListAdapterGoodsSub eLVGoodsSub = new ExpandableListAdapterGoodsSub(context, gs.getGoodsDetailSegment());
elv.setAdapter(eLVGoodsSub);
.
.
.
这里是我希望使用的代码,以便第一级 ExpandabaleListView 不会部分隐藏内部 ExpandableListView
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);
ExpandableListAdapterGoodsSub eLVGoodsSub = new ExpandableListAdapterGoodsSub(context, gs.getGoodsDetailSegment());
elv.setAdapter(eLVGoodsSub);
ClassCastException 的问题结束了
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);
【问题讨论】:
标签: android expandablelistview classcastexception baseadapter