I want to retrieve data from a MySQL database and populate a ListView in my Android application. I've seen answers on stackoverflow that use complicated methods of retrieving the data from a MySQL database using JSON objects. Instead, is there anyway I can use something similar to a MySqliteCursor to connect to a MySQL database? Is the Cursor Android class limited to using SQLite databases? If none of these options are possible, is there an easier way to populate a ListView with MySQL data?
See CursorAdapter class. It receive cursor, db column indicies and ids of widgets of view. Then it take data from db and populate corresponding fields
Yes, it receive Cursor from sqlite. You can easily implement adapter for any data- just know number of rows and query row under particular index. See RecyclerView tutorial (updated listview)
Related
In my Android application, I am using Sqlite DataBase to store the data from the server. I am using ContentProvider and ContentResolver to access the data from the DataBase and using CursorAdapter to bind the data to the ListView. As soon the data is inserted into the DataBase, CursorAdapter will be notified to update the ListView. Also, whenever I scroll the ListView, I get new data from the DataBase table and ListView will be updated. But once I reaches to the end of the table row, I need to fetch the data directly from the server without storing into the DataBase and update it in the ListView. Now as I am using CursorAdapter which accepts Cursor data, how can I bind a new set of data which is not coming from the DataBase? Is is possible to create Cursor data without getting data from the DataBase and use ChangeCursor() method in the ContentProvider to update the ListView? If not, is there any other method to achieve the same?
Is is possible to create Cursor data without getting data from the
DataBase and use ChangeCursor() method in the ContentAdapter to update
the ListView?
Yes, you can create cursor using MatrixCursor. If you will have to merge MatrixCursor with database Cursor use MergeCursor.
I want to fill my ListView with data that's going to come from the web in the form of JSON. The list should be theoretically infinite, with the app making requests for more data if scrolled to the bottom.
Should I use a Cursor or an Array(List) adapter to link my online database with my ListView?
More generally, what are the arguments to consider when choosing between cursor and array?
Well I think you should look at ContentProviders. They are more natural to the problem that you are trying to solve. You have to implement your custom Cursor which ContentProvider returns on a query request.
Ref:
http://developer.android.com/guide/topics/providers/content-providers.html
I am currently implementing a ListFragment backed by a CursorLoader that reads a database table via a Provider.
I need it to..
Have a last row in the list view that when the user clicks, loads more data to the database.
The database data is fetched in a background process from the server (I am thinking of doing this in an extended CursorLoader.loadInBackground() implementation, then returning the Cursor once the data has populated the database.
Are there any good examples of this, or is there a framework/project which has worked on this problem?
I'm making an application with a database of courses (of school) that the user is participating in. I want to display those courses in a list (im using listview) and use also the subitem (extra information of that course) of the listitems. I found a tutorial (http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/) that displays a list like I want but it uses a class to store the data in instead of a database. So the tutorial uses an arraylist of objects of that class. It would be a detour though if i had to put my information from my database into a class to put it in the list.
Does anyone have a clue how to solve this?
Thanks!
I found a beter way. By using a simple adapter and putting the values of the cursor in a hashmap in a arraylist. Found the idea from this site: http://eureka.ykyuen.info/2010/01/03/android-simple-listview-using-simpleadapter/
Here is a perfect tutorial for what you need. It shows you how to create a simple SQLite database and then populate a listview using the database.
SQLite Database creation and Listview Population Tutorial
I have an app that stores items in a local database, displayed to the user using a ListView, also in the layout is an EditText that can be used to filter the list. All of this works fine, my issue is I would also like to include items returned by a web service (JSON) in this list also. I'm not having an issue parsing the JSON, my issue is simply how do I insert/add the results from the web service to the ListView?
The data for the ListView comes from a cursor handled by a SimpleCursorAdapter, I just can not figure out how to add the items from the JSON results to the Cursor (I don't actually think you can write to a Cursor outside of performing a Query).
If you don't want to insert the JSON results into the local DB, then one approach would be to use an ArrayAdapter to back the ListView. You can then populate the array by inserting results from the cursor and the JSON query.
Hope this helps,
Phil Lello