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
Related
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 :
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).
WHAT I WANT TO ACHIEVE
=> Create an ANDROID app that shows the list of car manufacturers and the type of models they make. So when the user opens the app they see list of manufacturers. (ALL THIS DATA WILL BE LOADED FROM A DATABASE)
Like
1.Toyota
2.GMC etc..
So when they click on Toyota they will see the different cars Toyota makes (BY LOADING THEM FROM DATABASES). There would be sequence of screens displaying the different models .
SCREEN 1: Toyota Camry[A PICTURE , LITTLE DETAIL , AND A (VIDEO OR AUDIO) ]
SCREEN 2: Toyota Carina II[SAME THING HERE, (VIDEO OR AUDIO) , PICTURE AND DETAILS ABOUT CAR] etc...
So in each SCREEN there would be some kind of media related to THE CAR MODEL as shown above. A video or an audio promoting the car and some kind of text related to that model.
Now I'm downloading this information and want to save this kind of information of manufacturers and their cars in a database . I just cant come up with a good DB schema that let me safe this kind of data and let me load back to the screens .
--> If you can give me a general database schema like the number of tables I should have etc.. i would really appreciate.
SCHEMA I THOUGHT OF BUT DOESN'T LOOK GOOD
==>MANUFACTURERS TABLE[*MANUFACTURERS _ID , COMPANY_NAME , *MODELS ???HERE WHAT AM I MISSING ??? **]
==>MODELS_TABLE [*MANUFACTURERS _ID , MODEL_ID ,MODEL_NAME*]
==>RELATED MEDIA [*MODEL_ID , VIDEO_LOCATION , AUDIO_LOCATION , DETAILS_ABOUT_THE_CAR*]
AS YOU SEE AM JUST NOT GOOD WITH THE DESIGN :/ SO PLEASE HELP , THANKS IN ADVANCE
Any answer to this might be slightly subjective but my personal approach would be as follows...
Two tables called MANUFACTURERS and MODELS.
For the MANUFACTURERS table I'd have the following columns...
_id, company_name
For the MODELS table I'd have the following columns...
_id, manufacturer_id, model_name, description, video_uri, audio_uri
I've used _id for both tables as an Android Cursor needs a column called _id when used with Adapters. Create _id as UNIQUE PRIMARY KEY.
I also don't think it is necessary to have a separate table for the media as it relates directly to each model of car and the data can be included directly in the MODELS table.
I've used description as a generic term instead of DETAILS_OF_CAR and used _uri for the video and audio as it implies the media may be either stored locally or on a network server.
Other people might take a different approach but from what you describe this is the way I would do things.
Confused beginner here.
I'm extending the functionality of the android notepad tutorial program. I can successfully get the data from the sql to display in a list view and I can use the findNote function to get an individual note.
What I want to be able to do is extract an individual note AND all following notes in the table. I'd be happy with some way to iterate through the remaining notes (a puzzle for me because the rowIds are not sequential) but would also settle for designing a query that... I don't know, returns a String[] with the item with the matching id at position 0 and all subsequent items later in the array.
I'm sure there are a thousand ways to do this, I'm willing to take almost any of them. Please let me know if I need to clarify further.
Just looking at the NotesDbAdapter class in that tutorial, there doesn't appear to be any timestamp captured with the notes. You would need to extend the table structure to include this and update the createNote and updateNote methods to set that accordingly. Then you can write your SQL based upon that timestamp.
John
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!