Gallery ImageAdapter convertView is always null

前端 未结 3 1218
囚心锁ツ
囚心锁ツ 2021-02-02 15:57

I am using a Gallery with an ImageAdapter to load it with ImageViews that pull images out of my resources. My problem is that the convertView that gets passed to the getView() m

3条回答
  •  春和景丽
    2021-02-02 16:47

    No experience with that bug particularly, but I have done custom caching before with a 3rd party view pager (before the support lib).

    It's really not too difficult honestly. In my case, I knew there would be, at most, one item on the screen. But I also wanted the item to the left and right to be preloaded (these were webviews pulling data off the net). So I have a simple array of 3 views.

    [V1, V2, V3]
    

    Now the only thing you need to do is correlate a position in your adapter to a position in your cache. There's a variety of ways you could tackle this. When I first spiked it out, I just made whatever my current view was to be V2 and the rotated the items of the array around when flipping the pager. So flipping to the next view would alter my array

    [V2, V3, V1]
    

    Was simple to keep up with. Or you could just do the math and calculate a position to a relative position of the cache.

    Another approach is to create a last in, first out queue. Recycle views by pushing them into the queue, and when you need a view, just pop one from it.

提交回复
热议问题