2级自定义ExpandableListView ClassCastException

时间:2014-05-21 10:42:00

标签: android expandablelistview classcastexception baseadapter

我已经在Child和innerChild行中成功掌握了两级ExpandableListView和自定义布局。问题是第一级的组头显示良好。由于第一级ExpandableListView的高度,第二级的行部分显示。 第一级ExpandableListView托管一个布局,这个布局托管另一个ExpandableListView,后者又托管一个自定义布局,该布局有tableRow,动态填充数据。

我修改了位于http://harrane.blogspot.com/2013/04/three-level-expandablelistview.html的教程,建议使用自定义的ExpandableListView,它将在第一级ExpandableListView的适配器中使用。

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);

1 个答案:

答案 0 :(得分:0)

替换代码,

CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);

通过

CustomExpandableListView elv = new CustomExpandableListView(YourActivity Context);