I am new to Android and am trying to get my header round the SimpleCursorAdapter
and CursorLoader
classes. From my understanding, all of the examples that I have seen use these two classes to load data into a ListView
in a background thread (to not block the UI).
I am OK with this and have used this general approach with my own list of items, however I now want to be able to click on an item in the list and get the full information for the item. Is it usual practice to use SimpleCursorAdapter
and CursorLoader
to retrieve the details for a single item? or are they just meant for lists?.
Thanks.
android.widget.SimpleCursorAdapter. An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views. Binding occurs in two phases.
The difference being that instead of getting data from an Array it gets from the database. Another advantage of using CursorAdapter is that the number of items it fetches from the database is equal to the number which can be displayed on screen.
A CursorLoader is a specialized member of Android's loader framework specifically designed to handle cursors. In a typical implementation, a CursorLoader uses a ContentProvider to run a query against a database, then returns the cursor produced from the ContentProvider back to an activity or fragment.
They are not meant for lists only. You can - and should - use them in detail views (activities) as well.
I've sketched a possible way to do so on my blog: http://www.grokkingandroid.com/using-loaders-in-android/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With