Reputation: 1134
Helo.
I have the following requirement:
I have a list (ListView or Spinner depends on orientation) that shows all the projects in the database. This List works as a filter for the detail list of project associated data. This works fine (I use Loader and ContentProvider to get data). The Project list and Detail list are realised as separate fragments and communicate over the onProjectSelectedListener interface.
My requirement is: I need "ALL" as the first list item, to disable the filter and show all data (without project filter). How can I realise that (SQLite oder Android solution are welcome). The best i woud get onItemSelected a specific ID (e.g.: -100) for the "ALL"-Item.
Now
Project 1 (id: 1)
Project 2 (id: 2)
Project 3 (id: 3)
...
Required
ALL Projects (id: -100)
Project 1 (id: 1)
Project 2 (id: 2)
Project 3 (id: 3)
...
Upvotes: 0
Views: 430
Reputation: 1134
I solved the problem with a union view on SQLite database.
CREATE
VIEW all_projects AS
SELECT
-100 AS _id,
'ALL' AS pj_name,
'All Projects' AS pj_comment,
1 AS pj_is_active,
1 AS pj_all
UNION
SELECT
*,
1 AS pj_all
FROM
projects
The content provider make the select on the view if where statement has "pj_all" column and on tabel, if not.
if (!TextUtils.isEmpty(where) && where.contains(COLUMN_WITH_ALL)) {
queryBuilder.setTables(VIEW_ALL);
}
else {
queryBuilder.setTables(TABLE_NAME);
}
Upvotes: 0
Reputation: 1328
How about using MergeAdapter to combine your current CursorAdapter
(I'm guessing?) and a new ArrayAdapter<String>
that has your "All" option?
You can react to click events, etc. by simply extending MergeAdapter
instead of your current Adapter
.
Upvotes: 1