ANDROID : Load asynchronous pictures in listView

后端 未结 3 1094
不思量自难忘°
不思量自难忘° 2021-01-01 05:45

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.

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 06:17

    This happened to me too. What I figured out was that before the new image was getting bound to the imageview, the old one was displayed for a while. In your case, what is happening is that your correct info is showing onPostExecute(), which takes sometime, and before that whatever data was set in the convertview is being shown. There are 2 ways u could mostly fix this,

    In your getView(), change the if{}... else{} block to just

    layoutItem = (LinearLayout) mInflater.inflate(R.layout.auto_gi, parent, false);
    

    or

    set the imageview with some placeholder image in getView() till onPostExecute() is called.

    Hope this helps.

提交回复
热议问题