I have three tables:
Employees, Courses and Attendance (which links employees and courses).
I'm looking to get a listview (or other similar view), with a line for each employee and a 'column' for each course, with the date (from the link table) where attended. I'm struggling to work out how this can be done:
I can have run a query that gets a row for each employee-course combination, but that doesn't tie in to a row in the view for each employee (i.e. the query will return multiple rows for each listview row).
I can get the listview for each employee, but am not seeing how to then pull in the data for courses in via the linked table.
with no real direction I don't have code to post yet.
This can't be that uncommon a problem, but I'm not finding any examples: maybe I'm not thinking of the right phrases
What's best practice to achieve this sort of display?
For me best display should be ExpandedListview. Let say you have Employee that attended 3 courses. In ExpandableListview you for your GroupView set Employee data and for child data just set the course that it attended with information that you have in your table. Like in this image :
Related
I am trying to learn my ways around using Android way of doing things. So as a project I am building an app. I managed to do initial bits of layouts, forms fine. I am struck at the following.
Brief Overview
I have an Author class and Book class. A book can have multiple authors and like wise an author can write multiple books.
I have working layouts and activities for Authors and Books. Data is getting saved in sqlite db. (All good here)
I also have a layout screen for adding multiple authors for a book. There is a join table that holds multiple authors ids for a book. This table (BookAuthor) has following columns(_id, bookid, authorid). Example data is(1, 2223, 43)
Problem
When user enters the BookAuthor activity, they search and add multiple authors to the book. This is also working. My trouble is
how to display the list of authors with names that are already assigned to the book in the list view with a delete button
How to delete that entry from the join table when user clicks delete button for that listview row in the list
Can someone please point me in the right direction with good ref points or even short examples
Thanks
R
first question to SO, so please let me know if I'm stepping on any toes :)
This is a simplified version of my database:
CREATE TABLE products (_id INTEGER PRIMARY KEY, name STRING);
CREATE TABLE product_tag (product_id INTEGER, tag STRING, PRIMARY KEY(product_id, tag));
In one of my activities, I would like to list all products (one row per product) with all tags contained in the row, e.g.
bananas [yellow] [fruit]
ketchup [condiment] [red] [tomato]
mustard [yellow] [condiment]
The options I have considered are:
Using a SimpleCursorAdapter to list all products, querying product_tag in the ViewBinder for each row, and programmatically creating views for each tag and inserting them into the row.
Querying products LEFT JOIN product_tag ON products.id = product_tag.product_id, resulting in one row per tag (or one row per product with no tags) and manually populating the list. This seems more complicated and hacky, and duplicates some data, but avoids querying the db for each row in products.
I'd love it if someone more experienced with Android could comment on the most efficient way to accomplish this! Thanks in advance.
Definitely #2. Database access is slow, so you want to minimize the number of database queries.
I have:
Three tables: products, orders and order lines.
A CursorLoader and a CursorAdapter: ProductsOrderLoader and ProductsOrderAdapter.
ListView: a simple products listview.
For the time being, my list view shows products bought in a certain order (order lines), plus the rest of the products.
But these items are sorted by productName. What I want is to sort these products by quantity, however the quantity column belongs to another table orderLine.
Is it possible to stick to using CursorLoader and achieve the sorting of listview using a column present in another table?
I found an answer here: Get all the products, and putting a specific order's product first using only orderBy, without having to modify the ContentProvider.
I'm designing an android app that retrieve universities from online database I have to use ExpandableListView to represent them. I have 700 universities so I need to represent them by category . My categories are by letters A,B,C,D etc.
>L
London Metropolitan University
Lea Valley College
>M
Manchester College
Manchester University
I have problem populating the child elements in each category. Because I have a lot of data I think the best way is when each category is pressed to create sql query to get all universities starting with 'A' for example BUT all ExpandableListView example I found use arraylists or hashmaps with a few elements.
Thanks in advance for your time.
You could probably use CursorTreeAdapter.
See getChildrendCursor method:
If you want to asynchronously query a provider to prevent blocking the UI, it is possible to return null and at a later time call setChildrenCursor(int, Cursor).
I have in my db 2 table with a many to many relationship.
TAB_ARTICLES: {_ID, TITLE, BODY, DATE}
TAB_TAG: {_ID, NAME, COLOR, DATE}
TAB_ART_TAG: {_ID, ARTICLE_ID, TAG_ID}
I need to populate a ListView, one row for article and in every row I need to have a TextView for every label linked to that article. Like the following image
I think 2 solutions.
a. I use a CursorAdapter with a cursor made only on TAB_ARTICLE and than in every row I do a query to join the other 2 tables looking for all tags related at this article. This solution require a lot of db accesses.
b. I realize a temporary table
TABLE_TEMP: {ARTICLE_TITLE, ARTICLE_BODY, ARTICLE_DATE, TAG1_NAME, TAG1_COLOR, TAG2_NAME, TAG2_COLOR, ...}
and I use a query on this table as cursor for custom adapter. This solution use more space and have a limitation on possible displayed tags due to table columns.
Are there other ways?
Well, actually, it's a multicriterion thing: time, space, updates, search, etc. So there's no single recipe. It's very probable, however, that multiple queries will bog down scrolling. Worse, on some devices only. A temporary table may or may not be OK depending on the overall size of your data. And you may want to keep this redundant table in sync with the main one, making simultaneous updates to both.
One of the simplest trade-offs could be adding a redundant TEXT/CLOB column with the tag data (XML, JSON, other markup/separated format) to TAB_ARTICLES and keeping it in sync with your detail data. By the way, you will really need the M:M schema only if your queries substantiate that. Otherwise, the single table would suffice.
Again, I'd list and evaluate all the criteria first and decide what dimensions really need to be scalable and simplify the rest.