我在填写ImageView
时遇到了问题ListView
。
问题是,所有的图像被填充在相同的地方(在最底部的列表项的图像视图)。我可以看到图像在被填满时快速加载。所有图像都被加载到ListView中的相同位置
public class TheaterListAdapter extends ArrayAdapter<ConstantsTheaterList> implements IResult {
private ViewHolder viewHolder;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView==null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.fragment_theater_list_item, parent, false);
viewHolder = new ViewHolder();
viewHolder.imageView = (ImageView) convertView.findViewById(R.id.theater_list_item_image);
viewHolder.textViewLatitude = (TextView) convertView.findViewById(R.id.theater_list_item_latitude);
viewHolder.textViewLongitude = (TextView) convertView.findViewById(R.id.theater_list_item_longitude);
viewHolder.textViewVicinity = (TextView) convertView.findViewById(R.id.theater_list_item_vicinity);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
//Picasso.with(getContext()).load(uri.toString()).into(mImageView); [WORKS FINE]
// Using Volley to fetch image from the web.
new VolleyService(mContext, this).volleyImageRequest(uri.toString(), 100, 100);
String latitude = getItem(position).latitude;
String longitude = getItem(position).longitude;
String vicinity = getItem(position).vicinity;
viewHolder.textViewLatitude.setText(latitude);
viewHolder.textViewLongitude.setText(longitude);
viewHolder.textViewVicinity.setText(vicinity);
return convertView;
}
//These are the callbacks that I receive in my Volley implementation. Now, I fill the bitmap once they are available.
@Override
public void notifySuccess(Object response) {
Bitmap bitmap = (Bitmap) response;
viewHolder.imageView.setImageDrawable(bitmap);
}
@Override
public void nofifyError(Object volleyError) {
Log.e(TAG, (String)volleyError);
}
private static class ViewHolder{
ImageView imageView;
TextView textViewLatitude;
TextView textViewLongitude;
TextView textViewVicinity;
}
}
我相信被回收这一定是因为意见。
但是,当我使用毕加索时,一切正常。
我该如何解决这个问题?
“问题是,所有的图像被填充在同一个地方” - 这是因为你没有将图像填充到正确的'ViewHolder'中。不是使用与请求相关联的'ViewHolder',而是使用'viewHolder'字段中的任何'ViewHolder',它将是您最近遇到的任何'ViewHolder'。您需要更好地将Volley请求绑定到相关的“ImageView”。就我个人而言,我只是使用毕加索。 – CommonsWare
@CommonsWare请详细回答先生。我没有得到正确的。 –
@SumitJha在getView方法中,您正在使用凌空异步加载图像。在齐射加载图像时,视图持有者指向的位置被改变。 要解决这个问题,您可以使用图像加载库,使用recyclerview或创建排球服务时使用匿名类。 –