tags:

views:

961

answers:

2

I would like to make a custom CursorAdapter that takes a cursor and provides an extra summary row at the end. Such that given a Cursor with 4 rows, the ListView will contain 5 rows, the 4 rows from the cursor, plus a fifth row that contains some totals from the previous 4 rows. From the documentation I'm not clear on which methods to override to get this done. Or maybe there's a better way to do this..

+1  A: 

You can easily accomplish this by using the MergeCursor class, pass the original cursor as the first element on the array to the constructor and create a new simple AbstractCursor subclass that returns only the one item you are appending and pass it as the second element for the array in the constructor. Everything should work automatically for you then.

Franklin Munoz
+2  A: 

Mr. Munoz's answer is good. Another option, instead of changing the Cursor, is to use addFooterView() to add another row on your list that does not come from your Cursor data.

CommonsWare
So I would need a data observer on the cursor that would call addFooterView() when the cursor changed? Would that look seamless, or would the user see 4 rows and then see the fifth row added?
Aaron
You would add the footer view before adding the list adapter. You would update the footer view with new data whenever you wish, such as from a data observer.
CommonsWare
I like this solution a little better than the other, because I could use a different layout for the footer view.
Aaron