我在填寫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或創建排球服務時使用匿名類。 –