9

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?

Tianxiang Xiong
  • 3,887
  • 9
  • 44
  • 63

1 Answers1

19

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;
Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
Eric Levine
  • 13,536
  • 5
  • 49
  • 49
  • 1
    Hi elevine, as far as I can tell there are only 2 constructors, one of which requires API 11. So deprecation of the other basically means that an application targeted towards API 10 should not use `SimpleCursorAdapter`, right? Or am I missing something here? – Tianxiang Xiong Aug 13 '11 at 20:24
  • 1
    Not quite. The *right* thing to do in your case is to use LoaderManager and CursorLoader via the Compatibility Library that I provided a link for. Otherwise, you *can* use the deprecated constructor, its just discouraged. – Eric Levine Aug 13 '11 at 20:39
  • This seems weird. I'm just starting to play around with it and wondering why they would depreciate the only constructor that works with the phones(API 11 is honeycomb, which is tablet) and not provide a non-depreciate Constructor. – Nicholas Aug 14 '11 at 16:53
  • nowadays the compatibility package has become standard.. it's a bit wierd perhaps, but thats the way things are :) – Karl Jul 12 '12 at 09:49
  • 3
    @Nicholas You can use the non depreciated constructor on older versions using the compatibility library: import android.support.v4.widget.SimpleCursorAdapter; – M.ES Feb 20 '13 at 18:05