2 xiliaoxia xiliaoxia 于 2014.05.06 08:28 提问

convertView cannot be resolved to a variable

public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
ImageView iv1;
if(convertView == null)
{
iv1 = new ImageView(head.this);
iv1.setAdjustViewBounds(true);
iv1.setMaxHeight(150);
iv1.setMaxWidth(158);
iv1.setPadding(5, 5, 5, 5);
}
else
{
iv1 = (ImageView)convertView;
}
iv1.setImageResource(arg0);
return iv1;
}

3个回答

cnmusan
cnmusan   2014.05.06 08:57

convertView不能被转换成一个变量

xiliaoxia
xiliaoxia convertView原来是参数二 打扰了...
接近 4 年之前 回复
xiliaoxia
xiliaoxia 那要如何解决
接近 4 年之前 回复
wangchun8926
wangchun8926   2014.05.10 19:24

public View getView(int arg0, View arg1, ViewGroup arg2)改为
public View getView(int arg0, View convertView, ViewGroup arg2)

u013415968
u013415968   2014.05.15 11:12

listView 优化?? 还是啥?

ListView优化 内部类方式
public View getView(int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
ViewHolder viewHolder = null;
if(convertView==null){
viewHolder = new ViewHolder();
convertView = LayoutInflater.from(c).inflate(R.layout.list_item, null);
viewHolder.image = (ImageView) convertView.findViewById(R.id.item_image);
viewHolder.name = (TextView) convertView.findViewById(R.id.item_name);
viewHolder.path = (TextView) convertView.findViewById(R.id.item_path);
convertView.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) convertView.getTag();
}

        viewHolder.image.setImageDrawable(DrawAbleUtil.getBitmap(list.get(position).getPath()));
        viewHolder.name.setText(list.get(position).getName());
        viewHolder.path.setText(list.get(position).getPath());

    return convertView;
}

class ViewHolder{
    ImageView image;
    TextView name,path;
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!