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个回答

convertView不能被转换成一个变量

xiliaoxia
xiliaoxia convertView原来是参数二 打扰了...
接近 6 年之前 回复
xiliaoxia
xiliaoxia 那要如何解决
接近 6 年之前 回复

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

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
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问