水平列表视图从 URL 加载相同的图像(使用 Picasso)
Horizontal Listview Loading same images from URL (Using Picasso)
我已经剪掉了这段代码。它是一个水平列表视图。问题是正在加载相同的图像而不是不同的图像。可能是什么问题?我不认为毕加索是这里的问题。我猜是别的东西。
@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;
}
您没有在 getView
函数内的任何地方使用 position
的值。 getView
应该 return 位于您传入的数组或列表中索引 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;
}
我已经剪掉了这段代码。它是一个水平列表视图。问题是正在加载相同的图像而不是不同的图像。可能是什么问题?我不认为毕加索是这里的问题。我猜是别的东西。
@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;
}
您没有在 getView
函数内的任何地方使用 position
的值。 getView
应该 return 位于您传入的数组或列表中索引 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;
}