简体   繁体   English

如何为单个 ListView 创建多个适配器?

[英]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?内容存在于 ListView 中,因此需要一个适配器,内容不同,包含从 URL 加载的图像,我制作了不同的适配器来匹配不同的内容,并通过为用户设置目标适配器让 ListView 在它们之间切换已在菜单中按下,并且在每次按下时都会发生这种情况,但问题是每次我为 ListView 设置目标适配器时,内容中的这些图像都会从 URL 重新加载,因为 GetView() 方法已在每次调用适配器中的时间,那么我能做些什么来防止它们重新加载? 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 或 Picasso 在不同的列表视图中加载图像。 Glide internally caches images using their url as a key to retrieve cache. Glide 在内部使用它们的 url 作为检索缓存的键来缓存图像。 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.您可以创建自己的图像视图工厂,并在其中填充内容(图像),并根据唯一键(您将定义自己可能会很痛苦)获取此类视图,但这对于很少的结果来说是矫枉过正的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何将两个适配器添加到一个listView(Xamarin Android) - how i can add two adapters to one listView (xamarin android) 如何将ListView绑定到存储在WPF中的单个ViewModel中的多个集合? - How to bind a ListView to multiple collections stored in a single ViewModel in WPF? 如何使用WPF将单个ListView列与多个数据库表绑定 - How to bind a single listview columns with multiple db tables using Wpf 将多个数据源绑定到单个ListView - Binding multiple DataSources to a single ListView 在单个ListView中显示多个模型 - Showing multiple models in a single ListView 客户端如何与具有多个适配器的计算机上的Windows服务通信? - How does a client communicate with a Windows Service on a machine with multiple adapters? 如何使用适配器将自定义字体设置为ListView项中的TextView之一? - how to set custom font to one of the TextView's in ListView item using adapters? 如何在ListView绑定中创建/注册view / vewmodel的多个实例? - How to create/register multiple instances of view/vewmodel in a ListView binding? 如何在Xamarin.Forms中创建多列ListView? - How to create multiple columns ListView in Xamarin.Forms ? 带有GridView WPF的多行和单行选择列表视图 - multiple and single row selection listview with a gridview wpf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM