Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for SimpleCursorAdapter?

I'm looking at the Notepad Tutorial on the Android developer's site and noticed that SimpleCursorAdaptor is deprecated.

The new constructor

public SimpleCursorAdapter (Context context, int layout, 
    Cursor c, String[] from, int[] to, int flags)

is only available in API 11.

The suggested alternative is to use LoadManager with a CursorLoader, but these also require API 11. So what can replace SimpleCursorAdapter in API 10, i.e. how should Step 12 of the tutorial be done using a non-deprecated method?

like image 536
Tianxiang Xiong Avatar asked Aug 13 '11 18:08

Tianxiang Xiong


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.

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.


1 Answers

Please note that the deprecation does not apply to all ofSimpleCursorAdapter, just one of the constructors.

If you wish to use the Loader from API 11, you can pull in the compatibility library (see: http://developer.android.com/sdk/compatibility-library.html). This provides a backport that is compatible with API level 4 or higher devices.

EDIT :

If you are still facing the errors after using compatibility library, then you just need to replace

import android.widget.SimpleCursorAdapter;

with

import android.support.v4.widget.SimpleCursorAdapter;
like image 200
Eric Levine Avatar answered Sep 29 '22 16:09

Eric Levine