android listiem recycle while scroll up or down

我们两清 提交于 2019-12-25 02:58:39

问题


I am using complex list item as following to lazy upload image i am loading every list item's image in separate asyntask so that it won't hang the application while loading image.

problem comes when i scroll down the list new lisitems image had replace image effect when i drill down i found that

for example if by default 5 listitems fit onto the screen when i scroll down next displayed listem is actually the recycle of the previous listitem which was displaying thats why also containing the image of the previous listitem untill new image loaded, after new image loaded from web image get replaced and user found replace image effect when doing scroll up or scroll down every time images are getting replaced due to recycling...

Is there a way i can ask android to do not recycle the listitem when i scroll down or up so that it will not have replace image effect.

any good suggestion is appriciated

alt text http://www.freeimagehosting.net/uploads/8237cbd584.jpg


回答1:


My understanding is that you use getView() method from your adapter to provide your own layout for list item. So probably you have something like this:

public View getView(int position, View convertView, ViewGroup parent) {

        if(null == convertView){
            convertView = mInflater.inflate(R.layout.row, null);
            //...               
        }
        //... setting new values for your widgets
        return convertView
    }

If that is the case, then it is your call to recycle items. Such implementation prevents garbage collector to be called to often, but if it's not a problem and you can bear with GC, then you can just get rid of if(null==convertView) and construct your item from the scratch - every time getView method is invoked.

But probably that is not a good idea, it would be better if you retrieve your image widget from recycled item, set some temporary image and then start your async task to download the proper image.
Regads!



来源:https://stackoverflow.com/questions/1919679/android-listiem-recycle-while-scroll-up-or-down

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!