将发票清单处理为多列数组列表的最佳方法?
我创建了一个 SQLite 数据库,在这个数据库中是一整套发票,每张发票都有一个客户 ID 或供应商 ID,具体取决于发票是销售还是费用。
基本上,我想做的是查询数据库,通过选择的任何客户 ID 或供应商 ID 获取所有发票的列表,并在多列列表视图中显示该客户或供应商的所有发票。我已经创建了多列列表视图,它由每行的 xml 模板驱动,该模板基本上是一个带有 4 个文本视图的线性布局,每列一个。
话虽这么说,我想用每张发票中有 4 个值来填充列表视图。我假设如果我创建一个 ArrayList,将每个发票添加为它自己的行(也是每个发票所需的 4 个值的数组),我将得到一个漂亮且简单的多维 ArrayList,我可以简单地循环以填充列表视图。
在深入研究代码之前,我想确保这是最好的方法,也许我缺少一个方法?我很惊讶我找不到多列列表视图,所以你永远不知道!
谢谢!
I have created a SQLite DB, in this DB is a whole wack of invoices, each invoice has a customer ID or supplier ID depending on if the invoice is a sale or an expense respectively.
Basically, what I am trying to do is query the DB, grab a list of all invoices by whatever customer ID or supplier ID is selected, and display all the invoices for this customer or supplier in a multi-column listview. I have already created the multi-column listview, it is driven by an xml template for each row which is basically a linearlayout with 4 textview's, one for each column.
This being said, there are 4 values from each invoice I would like to populate the listview with. I assume that if I create an ArrayList, add each invoice as it's own row (also an array of the 4 values I need per invoice), I will get a nice and easy multi-dimensional ArrayList that I can simply loop through to populate the listview.
Before I dive into the code, I want to ensure this is the best approach, perhaps there is a method I am missing? I was surprised I couldn't find multi-column listviews, so you never know!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 ListView 旨在显示 SQLite DB 中的项目,您需要编写
CursorAdapter
而不是将整个结果集读取到 ArrayList 中。 CursorAdapter 可以有效地显示查询中的每一行,并帮助您轻松反映用户查看数据时发生的支持数据的任何更改。您可能还对 Google I/O 演讲感兴趣,该演讲介绍了 ListView 的基础知识:http://www.google.com/events/io/2010/sessions/world-of-listview-android.html
If your ListView is meant to show items from a SQLite DB you want to write a
CursorAdapter
instead of reading the whole result set into an ArrayList. CursorAdapters can display each row from a query efficiently and help you easily reflect any changes to the backing data that happen while the user is viewing it.You may also be interested in this Google I/O talk that goes over the basics of ListView: http://www.google.com/events/io/2010/sessions/world-of-listview-android.html