【问题标题】:2 level customised ExpandableListView ClassCastException2级自定义ExpandableListView ClassCastException
【发布时间】: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


    【解决方案1】:

    替换代码,

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

    由,

    CustomExpandableListView elv = new CustomExpandableListView(YourActivity Context);
    

    【讨论】:

    • 它不显示内部 ExpandableListView。 innerExpandable listView 使用自定义布局,其中包含 TableRow。此方法用于显示没有自定义布局的默认 ExpandableListView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 2014-05-13
    相关资源
    最近更新 更多