我已经成功地掌握了在子行和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。
下面是在第一级可展开列表视图中不使用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);发布于 2014-05-21 18:46:13
替换代码,
CustomExpandableListView elv = (CustomExpandableListView) v.findViewById(R.id.eLV_bols_details_goods_list_item);通过,
CustomExpandableListView elv = new CustomExpandableListView(YourActivity Context);https://stackoverflow.com/questions/23780882
复制相似问题