2015-02-06 101 views
1

我已經剪掉了這段代碼。它是一個水平列表視圖。問題是相同的圖像被加載而不是不同的圖像。可能是什麼問題?我認爲畢加索不是這裏的問題。我猜它是別的。水平列表視圖從URL加載相同的圖像(使用畢加索)

@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

你不使用你getView函數中的任何地方position價值。 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; 
}