简体   繁体   中英

How to create multiple adapters for a single ListView?

What I want to do is simple application that shows a menu which let the user switch between contents by selecting different topics in that menu(如图片)

The content exists in a ListView, so it needs an adapter, the contents are different and contains images that loading from URL, I have made different adapters to match the different contents and let ListView switch between them by setting the target adapter for what the user has pressed in the Menu, and that happens in each pressing time, but the problem is that in each time I set the target adapter for the ListView those images in the contents reload from the URL because the method GetView() has being recalled in each time in the adapter, so what I can do to prevent them from reloading? I know I can create multiple list views but I think that isn't a good way..

Cache the images on the filesystem when you first download them. When you load an image, check the cache, and download the images only if they're not yet cached. If they are, load them from the filesystem instead.

Try using glide or Picasso to load images in different list views. Glide internally caches images using their url as a key to retrieve cache. That way when your images are loaded once in any of your list view, they can be cached for future use in other list views. However, you will still need to create new instances of the image view as you will be using a completely different listview. You CAN create your own factory of image view with content (image) populated inside them and get such views based on unique keys (that you will define yourself which can be pain) but that would be an overkill for very little outcome.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM