水平Listview从URL加载相同的图像(使用Picasso)

时间:2015-02-06 03:54:13

标签: android picasso horizontallist

我已经破解了这段代码。它是一个水平列表视图。问题是正在加载相同的图像而不是不同的图像。可能是什么问题?我不认为毕加索是这里的问题。我想其他的东西。

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
//      View timeLineRow = LayoutInflater.from(parent.getContext()).inflate(R.layout.dashboardtimelinerow, null);
        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = mInflater.inflate(R.layout.toprecommendationsitem, parent, false);

            holder = new ViewHolder();
            holder.recommimage = (ImageView) convertView.findViewById(R.id.recommimage);
            holder.userImage = (CircularImageView) convertView.findViewById(R.id.userImage);

            convertView.setTag(holder);
        } else
            holder = (ViewHolder) convertView.getTag();
        int i=0;
        for(i=0; i<mArrayListData.size(); i++) {
            if (!mArrayListData.get(i).getDishimageurl().isEmpty()) {
                Picasso.with(mContext)
                        .load(mArrayListData.get(i).getDishimageurl())
                        .resize(172, 172)

                        .into(holder.recommimage);
                break;

            }
        }

        return convertView;
    }

1 个答案:

答案 0 :(得分:1)

您未在position函数内的任何位置使用getView的值。 getView应该返回您传入的数组或列表中索引position处的任何数据片段的视图。您需要用

之类的代码替换代码
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.toprecommendationsitem, parent, false);

        holder = new ViewHolder();
        holder.recommimage = (ImageView) convertView.findViewById(R.id.recommimage);
        holder.userImage = (CircularImageView) convertView.findViewById(R.id.userImage);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    if (!mArrayListData.get(position).getDishimageurl().isEmpty()) {
        Picasso.with(mContext)
                 .load(mArrayListData.get(position).getDishimageurl())
                 .resize(172, 172)
                 .into(holder.recommimage);
    }

    return convertView;
}