[英]Creating Multi-Column Layout with ArrayAdapter
I've been trying to fix this problem for a while and have exhausted all the different Google searches that I could think of.我一直在尝试解决这个问题一段时间,并且已经用尽了我能想到的所有不同的谷歌搜索。 I'm a beginner with Android, but understand most of the fundamentals (I think).
我是 Android 的初学者,但了解大部分基础知识(我认为)。 Anyways, I'm trying to display a list of data in a multi-column layout spreadsheet style.
无论如何,我正在尝试以多列布局电子表格样式显示数据列表。 I'm using a ListView for that because I need users to be able to click on a row to get a more detailed look at the data since only so much can fit in a row.
我为此使用 ListView,因为我需要用户能够单击一行以更详细地查看数据,因为只有这么多可以放在一行中。 I have it working perfectly using a SimpleAdapter, but since the amount of data can sometimes be large, up to 500 entries, I wanted to change over to a Lazy Loader system so users don't have to stare at a black screen for 20 seconds while everything loads.
我使用 SimpleAdapter 让它完美地工作,但由于数据量有时可能很大,最多 500 个条目,我想切换到延迟加载器系统,这样用户就不必盯着黑屏 20 秒当一切都加载时。 I think I can manage with the Lazy Loader part, but I can't figure out how to switch over from my multi-columned format SimpleAdapter to an ArrayAdapter that all the Lazy Loader examples use.
我想我可以使用 Lazy Loader 部分进行管理,但我不知道如何从我的多列格式 SimpleAdapter 切换到所有 Lazy Loader 示例使用的 ArrayAdapter。
Here's an example of my SimpleAdapter code:这是我的 SimpleAdapter 代码的示例:
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to); SimpleAdapter 适配器 = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
fillMaps is the List of HashMaps that are to be inserted. fillMaps 是要插入的 HashMap 列表。 'grid_item' is the layout that the entries are inserted into.
'grid_item' 是条目插入的布局。 'from' is an array of column names (alternatively the keys in the HashMap) to be used.
'from' 是要使用的列名数组(或者 HashMap 中的键)。 'to' is an array of TextView items that will be filled in 'grid_item'.
'to' 是一个由 TextView 项目组成的数组,它们将被填充到 'grid_item' 中。 Any idea how to convert this to an ArrayAdapter?
知道如何将其转换为 ArrayAdapter 吗? Or how to Lazy Load with a SimpleAdapter?
或者如何使用 SimpleAdapter 进行延迟加载?
Thanks in advance!提前致谢!
To solve this issue for others, here is what I did to get it working perfectly:为了为其他人解决此问题,这是我为使其完美运行所做的工作:
To get the lazy loading working:要使延迟加载工作:
Just write your own adapter.只需编写自己的适配器。 Create a private a class in your
Activity
that houses your ListView
that extends BaseAdapter
.在您的
Activity
中创建一个私有的 class ,其中包含扩展BaseAdapter
的ListView
。 Fill out the abstract methods and display your data however you want to.填写抽象方法并根据需要显示数据。 As useful as
SimpleAdapter
obviously is, you'll get a lot more traction out of your own adapter, and they're really not difficult to write. SimpleAdapter
显然很有用,你会从你自己的适配器中获得更多的牵引力,而且它们真的不难编写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.