首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >2级自定义ExpandableListView ClassCastException

2级自定义ExpandableListView ClassCastException
EN

Stack Overflow用户
提问于 2014-05-21 18:42:00
回答 1查看 319关注 0票数 0

我已经成功地掌握了在子行和innerChild行中自定义布局的两级ExpandableListView。问题是第一级的组头显示得很好。显示第二级的行部分是因为第一级ExpandableListView的高度。第一级ExpandableListView托管一个布局,此布局托管另一个ExpandableListView,后者又托管一个自定义布局,该布局具有应动态填充数据的tableRow。

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

代码语言:javascript
复制
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。

下面是在第一级可展开列表视图中不使用CustomExpandableListview类时的代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);

    ExpandableListAdapterGoodsSub eLVGoodsSub = new ExpandableListAdapterGoodsSub(context, gs.getGoodsDetailSegment());
    elv.setAdapter(eLVGoodsSub);

ClassCastException的问题已经解决了

代码语言:javascript
复制
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);
EN

回答 1

Stack Overflow用户

发布于 2014-05-21 18:46:13

替换代码,

代码语言:javascript
复制
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);

通过,

代码语言:javascript
复制
CustomExpandableListView elv = new CustomExpandableListView(YourActivity Context);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23780882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档