android expandable list from online database - android

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).

Related

Android SQLITE search VS ArrayList search for small amount of dataset

Suppose, In my app I have a sqlite table that can contain at most 20 row. Each row has 2 column(id, name). Where I frequently need to search by Id to get Name. For this frequent need I have two solution:
Solution 1: Get rows in a arraylist<model> and then find name from array.
Solution 2: Every time search on sqlite table.
Now please give your opinion which one is better?
Remember again, I need this search in my recycleView item, so it call so frequently.
Thanks
I don't really get what is your real intent, but if your task is to search by id often, I would use
LongSparseArray<String> idsToNames; // or LongSparseArray<Model>
Which will map primitive long to Strings in a more memory-efficient way than Map and will have a better performance than ArrayList when searching.
The advantage over querying SQLite here is that you can do it in a blocking manner instead of having to query database on a background thread every time the lookup runs.
The disadvantage is that whenever data changes in SQLite, you will have to rebuild your idsToNames map. Also, if the number of entries in SQLite will eventually grow, you will end up in a large collection. So I would recommend this approach only if the updates to the database during this session will not happen, and if the data size is always predictable or fixed.

listview with linked tables (many to many relationship)

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 :

Android One to many

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

Magical join, or refresh multiple objects at once?

I have some Items with a foreign key to a parent Category. Is there an efficient way to query some Items and get fully populated Category objects?
The only approach I'm aware of is to use foreignAutoRefresh, or to refresh the Categories manually after the Item query, but this would result in an extra db hit for EACH Item object.
This can be done with a single JOIN, but if I do that is there any support for automatically building out the Category objects? Part (maybe all) of the problem is I don't fully understand the QueryBuilder's join functionality, but based on this answer it sounds like it doesn't do this:
Notice, however, that you can only get entities from the query builder
using this mechanism. If you want to get your two description fields
from different objects then you would have to still use a raw-query.
Alternatively, is there a way to refresh a collection of Categories in place with a single query, so that I can take the bare id-only Categories from the Item query and refresh them all?
In case it's of interest, the goal is to display these hierarchically in an ExpandableListView. Please let me know if I can provide any more info. I am comfortable throwing some SQL at it and populating Java objects myself if need be, but I'd rather stay within the framework if possible.

Retrieving Database Information and Showing in ListView with Android

I am working on an Android app that will allow the user to see restaurants in the city I live in. I am storing each restaurants information (name, address, telephone, hours, category, website) in an SQLite database.
What I am trying to do is to create a SortByAlpha activity that will list the restaurants by name in alphetically-descending order.
I understand that I should be using a Cursor to do this but I can't find a half decent tutorial, all of the "tutorials" I find are a bunch of code with minimal explanation. How can I do this / Where can I find a good tutorial?
Use SimpleCursorAdapter, which bridges between Cursor and Adapter. Here is an example how to use it: http://developer.android.com/guide/topics/ui/binding.html
I would advise creating a "Restaurant" class that contains all the fields you will be listing. Then make your SQL call and specify "ORDER BY Name". Then create an ArrayList that can be fed to your custom list adapter! Also, if they were to somehow get out of order, just implement the "Comparable" interface for the Restaurant class and compare based on "Name" and then you can call Collections.sort(restaurantlist); to sort them in alphabetical order. I personally think ORDER BY is the easier way to go!

Categories

Resources