Usin SimpleCursorAdapter confusion - android

I have a ContentProvider implementation in my app which works fine. I have a table called elements where the user can store a bunch of information.
What I am doing is when the user opens the app, I pull this data out of the database, process it using the display options set by the user (Like change the string formats, time formats, date formats, number decimals etc), and then put it in ListFragment which using my own implementation of ArrayAdapter. User can of course change the preferences in the middle of the session, where I reload the data and reformat it and present it to the user. The user can click on an item in the list, and see more details of that item. I accomplish this by overriding ListFragment.onListItemClick().
I have been reading about SimpleCursorAdapter. I am confused if the use of this would be more correct than using an ArrayAdapter for what I am doing. I am confused because I am not directly mapping the database data to the view. So should I be using a SimpleCursorAdapter? Also, the _ID column seems to be a requirement. I don't want to rename my table at this point. After a few articles and tutorials, I am not sure what to do. So any suggestions are appreciated.

Related

Saving Information Android

I am still fairly new to android and trying to learn day by day. I am trying to create a simple test application that you register for with an email/password to learn how to use save data from users.The app I am making is going to be simple, once they register and login, the user can search through a list of items I created on my MainActivity, and when they click on the listview item it will open a new activity. On the new activity, there will be a favorites button that I want to be able to click on and it will store that listview item information onto a favorites fragment I created and it will show the user a list of movies the user saved as favorites.
I am just trying to find out the best way I can do this. I have looked into SQLite and Firebase, hoping someone can explain to me which way would be the best way to approach this and maybe link me to a tutorial if possible.
Also the adding favorites to a listview item, if any one has a tutorial on that. I have already created my main listview and using Intents take the information and pass it to the new activity. It just clicking on the favorites button and saving the information into a new listview I do not know how to do, especially for when the users closes and re-opens the app the favorites will still be there.
Any help will be greatly appreciated.
To save favourite items in a new ListView you have to store the information somewhere. If you're using SQL, then store the Primary Key value in a favourites table that you can then use to find the corresponding information from the initial ListViews table.
If you are using firebase then each item in your list should have a unique key. Save that key and then when loading the favourites ListView, use the saved key to get the key's child data.
To summarise:
Store in a favourites table/branch the items the user selects as favourites and use that table/branch then to populate the favourites ListView.
I hope this helps
Another approach you could consider doing is storing your favorites using SharedPreference. The logic that would then follow is you have each row in your list view be an object that has an ID. Anytime a user favorites that object you save it into a set and store that set into SharedPreference that are corresponding to the current account username. You can then retrieve that set and show only the favorite objects for the user later on.
As for the SQLite vs Firebase question, I have not worked with Firebase yet, most of my interactions have been custom API calls. Having said that, I think SQLite would be a nice way to handle this as it would keep things easy and give you a good understanding of both sides of the equation.
Check out this tutorial. This very next one also covers SQLite:
https://www.youtube.com/watch?v=4SwAvFYMsXE

Select multiple object type with auto complete

I am looking for some help to find a powerfull way to allow selection of different List items.
My case is that i have for exemple a List profiles, List teams ... and i'd like to have an autocomplete input that will show, for exemple if i type Al, all Teams and Profiles objects having there member variable name begining by Al.
The result would be that i could get from the activity, on submit click performed, a List & a List containing all the objects who have been selected through the autocomplete form.
Also i'd like that the list offered to the user that match the chars he typed show the name and a picture (facebook like tag selection).
Obviously i am not asking for some code but at least some guidelines from experienced Android devs who know what to do and not to do to create this kind of thing.
Thanks
Loader are one of the best way to filter list. You init a loader which take the String constraint used for filter, the each time the user type, you update the constraint and restart your Loader.
If I suppose that all your object are cached in a SQLite database you can use a CursorAdapter, Cursor and CursorLoader.
You create the needed CursorLoader by filter the query with the content of the EditText.
If you're not familiar with CursorLoader there is the AsyncTaskLoader, with this you won't have the need of DB and to code a provider which can accept raw query. Your object in ListA, ListB, etc must inherits of common class (hum... DataThing maybe :-)), you concatenate the objects in a list then you can filter the list : What is the best way to filter a Java Collection?
That's for the data filtering. Now in order to display the data the way you want, you can display of list below the EditText field or create a custom component if you want a more advanced look.

Android Notepad Tutorial extension: getting more out of the (SQL) NotesDatabase

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

How to save database information to a file in android?

I have an application that uses a pre-polulated database to list events. The app allows people to save these events to their favorites by setting a '1' to the column isFavorite. Then the user can view only a list of 'favorited' events which searches for all rows that have isFavorite = 1.
If any changes happen to the events or I need to add more to the list, I have to make those changes and then push the update to the app which completely writes over the table, clearing out their favorites.
Is there any way that I can, on upgrade, save a list of id's of all the events that they have set to their favorites, then after the new database has been loaded, to set all id's in that list to 1 so the user doesn't lose their favorited data?
If there are any other better solutions to this problem I would really appreciate it, this has been the biggest hurdle for me so far.
I guess, you have a SQLiteOpenHelper-class? This class must be extended and then provides two functions: onCreate (which is called when the Database is queried and it doesn't exist (Normally creates your Database in the first place)) and onUpdate (which is queried when the Database structure should be updated).
The onUpdate-method has an SQLiteDatabase-Object parameter, which is your Database. You can then Query the information you need, save them and then create the new Database-tables. After that, you can insert your saved data back into the Database.
Can't you cope with thus in your DB design? Have a user favourites table that holds id's. So long as these id's don't change upgrade won't affect it surely?
One possible solution is backing up part or all of your database to restore at a later time. I found this guide quite handy http://www.screaming-penguin.com/node/7749
Alternatively, you may save their favorites as a SharedPreferences. http://developer.android.com/reference/android/content/SharedPreferences.html for more information on that.

Autocomplete list from SQLite with criteria

Can someone point me to right direction, how to create an adapter for AutoCompleteTextView, which would be getting data from SQLite DB, using data, which user entered into the text field? I want to use the user-entered data to filter suggestions for autocompletion. I imagine that adapter should always take user-entered data as soon as changes appears and use it for fetching suggestions on-the-fly. Is that possible? So far I've seen many tutorials for autocompletion where static String arrays were used, but never seen them build dynamically. Is it possible to do it automatically or I need always fetch String array myself and pass as ArrayList to adapter on every AutoCompleteTextView change?
You might be looking for CursorAdapter. Use it just like an ArrayAdapter, but instead of feeding it with an ArrayList, provide a database Cursor. Google for CursorAdapter and you should get a lot more example codes.

Categories

Resources