标签:
在expandListView的group中如果包含imageview发现,报错。提示无法将imageview转换成TextView.查看源码发现,SimpleExpandableListAdapter中有如下方法:
private void bindView(View view, Map<String, ?> data, String[] from, int[] to) { int len = to.length; for (int i = 0; i < len; i++) { TextView v = (TextView)view.findViewById(to[i]); if (v != null) { v.setText((String)data.get(from[i])); } } }
public class MyExpandableListAdapter extends BaseExpandableListAdapter{ private void bindView(View view, Map<String, ?> data, String[] from, int[] to) { int len = to.length; boolean isBound = false; for (int i = 0; i < len; i++) { final View v = view.findViewById(to[i]); if (v!=null) { final Object _data = data.get(from[i]); String text = _data == null ? "" : data.toString(); if (text == null) { text = ""; } if (mViewBinder != null) {//如果Binder不为空,使用Binder进行处理 isBound = mViewBinder.setViewValue(v, data.get(from[i]), text); } if (!isBound) {//如果Binder跳过,使用原来的方法进行处理 TextView _v = (TextView)v; _v.setText((String)data.get(from[i])); } } } } }
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { ItemViewHolder holder = null; if(convertView == null){ holder=new ItemViewHolder(); convertView = inflater.inflate(R.layout.down_exam_vitem, null); holder.itemImg = (ImageView)convertView.findViewById(R.id.exam_vitem_img); convertView.setTag(holder); }else{ holder = (ItemViewHolder)convertView.getTag(); } itemView = (RelativeLayout)convertView; return itemView; }
android expandlistview group imageview报错的解决办法
标签:
原文地址:http://blog.csdn.net/howlaa/article/details/45502957