I have a customized Cursor
based adapter for my ListView
. Each Cursor
has a few columns of data, sorted by the priority column.
I know you can create a disabled list item to act as a sort of header, like in the Market app (the little green labels).
开发者_如何学JAVAWhat I would like to do is display a header for each group of items with a different priority. They are already sorted by priority.
Example data:
title, priority
note1, high
note3, high
note2, low
note4, low
Example of what I want in ListView
:
===High Priority====
-note1
-note3
===Low Priority=====
-note2
-note4
Any ideas on how I could do this?
Since you're using Cursors you can try my SectionCursorAdapter.
See the source for an example how to use it.
Having heading rows in a ListView
is a matter of custom-crafting an appropriate ListAdapter
. Have areAllItemsEnabled()
return false
and implement isItemEnabled()
as needed.
Where things get tricky is in your chosen data model. Your ListAdapter
will need to return 6
from getCount()
, since you want six rows in your list. Your underlying data has four rows. That means you are going to have to write a fair bit of code to translate positions from what the ListView
thinks (6) to what your data thinks (4), and handling the header rows for the other two positions.
精彩评论