简体   繁体   English

将发票清单处理成多列ArrayList的最佳方法?

[英]Best way to approach Invoice Listing into Multi-Column 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. 我创建了一个SQLite数据库,该数据库中有大量的发票,每个发票都有一个客户ID或供应商ID,具体取决于发票分别是销售还是费用。

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. 基本上,我想做的是查询数据库,通过选择任何客户ID或供应商ID来获取所有发票的列表,并在多列列表视图中显示该客户或供应商的所有发票。 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. 我已经创建了多列列表视图,它由每行的xml模板驱动,该模板基本上是具有4个textview的线性布局,每列一个。

This being said, there are 4 values from each invoice I would like to populate the listview with. 话虽这么说,我想用列表视图填充每个发票中的4个值。 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. 我假设如果创建一个ArrayList,将每张发票添加为它自己的行(也是每张发票需要的4个值的数组),我将获得一个很好用的多维ArrayList,可以简单地循环遍历它来填充列表显示。

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! 谢谢!

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. 如果您的ListView旨在显示SQLite数据库中的项目,则您想编写一个CursorAdapter而不是将整个结果集读取到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. CursorAdapters可以有效地显示查询的每一行,并帮助您轻松反映用户在查看备份数据时发生的任何更改。

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 您可能还会对有关ListView基础的Google I / O演讲感兴趣: http : //www.google.com/events/io/2010/sessions/world-of-listview-android.html

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

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