Figuring out how to share the list is kicking my ass right now. I saw the code for sectioned-list-adapter here: ListView with scroll / fixed header lines , and that may be what I want in the end, but maybe there is a better way,
Here are the requirements I need:
- The data for listview must come from a SQLite database (see the following code for the table)
- Data should be grouped by month (bonus points for a month / year).
- The title bar should contain the number of items recorded in the database for that month.
- Must be compatible with API 8+
- you need to click an item to open a dialog box containing the steps performed on that day (I already know how to do this as soon as I can create a list)
Looking at Jeff Snarkey seperatedListAdapter here: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/ I was able to come up with the following:
datasource = new SmashDataSource(this); datasource.open(); BJJHistory = (ListView) findViewById(R.id.ListHistory); // create our list and custom adapter adapter = new SeparatedListAdapter(this); HistoryBJJ = datasource.getBJJHistory(); // THE DESIRED COLUMNS TO BE BOUND final String[] columns = new String[] { SQLiteHelper.DATE }; // THE XML DEFINED VIEWS WHICH THE DATA WILL BE BOUND TO final int[] to = new int[] { R.id.list_item_title }; if (HistoryBJJ != null) { adapter.addSection("October", new SimpleCursorAdapter(this, R.layout.list_item, HistoryBJJ, columns, to)); } BJJHistory.setAdapter(adapter);
In this order, the following cursor is used to retrieve data from the SQLite database in descending order:
public Cursor getBJJHistory() { final String[] columns = { SQLiteHelper.COLUMN_ID, SQLiteHelper.DATE }; final Cursor History; History = database.query(SQLiteHelper.TABLE_BJJ, columns, null, null, null, null, SQLiteHelper.DATE + " DESC"); return History; }
The result is the following:

This is good to start with, but presents two problems:
- How to dynamically populate the Title value with a month? I thought about using a cursor to populate an array with a list of months (after formatting them with SimpleDateFormat), then doing a For Each loop to go through each, passing a month ago to the cursor method to pull out all the records with the date and time value for that month.
- How to display the results in a row as the number of records for this day? Ideally, I would like something like this:

The answer to # 2 is quite simple, just put two text images in the list row layout, more complicated is how to group all the rows in the database for every day or at least do the count for each day and use this count to display in the list.
For the first, let's return to the code example here: http://code.google.com/p/android-section-list/ , instead of the presented array of examples, I think that it could possibly change the following:
SectionListItem[] exampleArray = { // Comment to prevent re-format new SectionListItem("Test 1 - A", "A"), // new SectionListItem("Test 2 - A", "A"), // new SectionListItem("Test 3 - A", "A"), // new SectionListItem("Test 4 - A", "A"), // new SectionListItem("Test 5 - A", "A"), // new SectionListItem("Test 6 - B", "B"), // new SectionListItem("Test 7 - B", "B"), // new SectionListItem("Test 8 - B", "B"), // new SectionListItem("Test 9 - Long", "Long section"), // new SectionListItem("Test 10 - Long", "Long section"), // new SectionListItem("Test 11 - Long", "Long section"), // new SectionListItem("Test 12 - Long", "Long section"), // new SectionListItem("Test 13 - Long", "Long section"), // new SectionListItem("Test 14 - A again", "A"), // new SectionListItem("Test 15 - A again", "A"), // new SectionListItem("Test 16 - A again", "A"), // new SectionListItem("Test 17 - B again", "B"), // new SectionListItem("Test 18 - B again", "B"), // new SectionListItem("Test 19 - B again", "B"), // new SectionListItem("Test 20 - B again", "B"), // new SectionListItem("Test 21 - B again", "B"), // new SectionListItem("Test 22 - B again", "B"), // new SectionListItem("Test 23 - C", "C"), // new SectionListItem("Test 24 - C", "C"), // new SectionListItem("Test 25 - C", "C"), // new SectionListItem("Test 26 - C", "C"), //
and replace it with cursors or the fact that you don’t need to retrieve data per day, instead of "A", "B", "C", replace it with the name of the month.
This is rather confusing for me, since I'm still learning, I got almost all parts of this application, I just can’t figure out how to split the data into a list
For reference, this is a screenshot of “CardioTrainer,” a training application that has a user section, but basically I'm trying to duplicate, at least in a function.

The table is as follows: 