1

I have a Spinner bound to a database column by a cursor. All the examples I have found suggest the use of the SimpleCursorAdapter which apparently is deprecated, so i have to use @SuppressWarnings("deprecation) in order to complile correctly. I have the following code that works correctly, but I don't like having to use a deprecated feature.

private Spinner  itemCategory;
itemCategory    = (Spinner) findViewById(R.id.itemCategory);

private void loadCategoryOptions() {

    Uri uri                     = Uri.parse(GoalsContentProvider.CONTENT_URI + "/categories");
    String[] projection         = { CategoriesTable.COLUMN_ID, CategoriesTable.COLUMN_NAME };
    String selectCriteria       = CategoriesTable.COLUMN_STATUS + " > 0";
    String sortOrder            = CategoriesTable.COLUMN_NAME + " ASC";
    Cursor cursor               = managedQuery(uri, projection, selectCriteria, null, sortOrder);

    @SuppressWarnings("deprecation")
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
                                                          android.R.layout.simple_spinner_item, 
                                                          cursor, new String[] { CategoriesTable.COLUMN_NAME },  
                                                          new int[] {android.R.id.text1});

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    itemCategory.setAdapter(adapter);
}

I am using the Android support v4 package. Any suggestions?

Lukuluba
  • 381
  • 1
  • 5
  • 18
  • Possible Duplicate: http://stackoverflow.com/questions/8790659/simplecursoradapter-deprecated-in-api-version-15 – Kuffs Apr 23 '12 at 13:31
  • `@SuppressWarnings` is not required, it's just a warning you hide, not an error. – zapl Apr 23 '12 at 13:34

1 Answers1

0

Only the constructor is deprecated not the whole class.

See SimpleCursorAdapter deprecated in API version 15?

Community
  • 1
  • 1
Kuffs
  • 35,581
  • 10
  • 79
  • 92
  • Wow, very simple! I just added a `0` as an extra argument to the constructor and the `@SuppressWarnings` was no longer required. Ref: [SimpleCursorAdapter deprecated in API version 15?](http://stackoverflow.com/questions/8790659/simplecursoradapter-deprecated-in-api-version-15).Thanks @Kuffs – Lukuluba Apr 23 '12 at 13:46