Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of Android SimpleCursorAdapter and CursorLoader

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.

like image 220
Umbungu Avatar asked Oct 26 '12 08:10

Umbungu


People also ask

What is SimpleCursorAdapter in android?

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.

What's the advantage of using a SimpleCursorAdapter?

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.

What is cursor loader in Android?

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.


1 Answers

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/

like image 132
Wolfram Rittmeyer Avatar answered Sep 28 '22 07:09

Wolfram Rittmeyer