ANDROID : Load asynchronous pictures in listView

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

I 'd like to display a ListView with a customized adapter (with picture and text).

Images are loaded from distant servers, so I have decided to use AsyncTask.

Actually, pictures are well displayed but if I scroll down quickly, a wrong picture is displayed during 1/2 secondes (after loading, correct picture appears)

Here is my adapter's code:

public class GiAdapter extends BaseAdapter {      private Context mContext;      private List mListAppInfo;     private HashMap views;     private HashMap oldPicts = new  HashMap();     private LayoutInflater mInflater;     private boolean auto;      private final String BUNDLE_URL = "url";     private final String BUNDLE_BM = "bm";     private final String BUNDLE_POS = "pos";     private final String BUNDLE_ID = "id";      public GiAdapter(Context context, List list) {         mContext = context;         mListAppInfo = list;         views = new HashMap();         mInflater = LayoutInflater.from(mContext);      }      @Override     public int getCount() {         return mListAppInfo.size();     }      @Override     public Object getItem(int position) {         return mListAppInfo.get(position).getId();     }      @Override     public long getItemId(int position) {         return mListAppInfo.get(position).getId();     }      @Override     public View getView(int position, View convertView, ViewGroup parent) {          LinearLayout layoutItem;          // reuse of convertView         if (convertView == null) {             layoutItem = (LinearLayout) mInflater.inflate(R.layout.auto_gi, parent, false);         } else {             layoutItem = (LinearLayout) convertView;         }          // infos for the current element         SiteStaff entry = mListAppInfo.get(position);          //set some text fields         TextView name = (TextView) layoutItem.findViewById(R.id.name);         TextView size = (TextView) layoutItem.findViewById(R.id.size);           name.setText(entry.getName());         size.setText(entry.getSize());          // get the imageView for the current object         ImageView v = (ImageView) layoutItem.findViewById(R.id.gi_image);          // put infos in bundle and send to the LoadImage class         Bundle b = new Bundle();          //url of the pict         b.putString(BUNDLE_URL, entry.getUrl());          //position in the listView         b.putInt(BUNDLE_POS, position);          //id of the current object         b.putInt(BUNDLE_ID, entry.getId());          //put info in the map in order to display in the onPostExecute         views        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!