0

I'm using the cursor.setExtras(bundle) function in my android project. It is working fine for api level 23. Since this function is available only for api level 23 and above, I've to find the alternative to set the Extra Bundle to Cursor.

Rohit Pal
  • 1
  • 4

2 Answers2

0

You can't use cursor.setExtras() in api below 23, so we need to use something else. I think there is a way to achieve this by using MatrixCursor:

MatrixCursor extras = new MatrixCursor(new String[] { "_id", "title" });
extras.addRow(new String[] { "-1", "New Template" }); 
extras.addRow(new String[] { "-2", "Empty Template" });
Cursor[] cursors = { extras, cursor };
Cursor extendedCursor = new MergeCursor(cursors);

This question help me to find an alternative solution: How to insert extra elements into a SimpleCursorAdapter or Cursor for a Spinner?

Community
  • 1
  • 1
zkvarz
  • 611
  • 1
  • 8
  • 18
0

You can instead override the getExtras() method and return the Bundle there. This works because getExtras() is available from api level 1.

MatrixCursor c = new MatrixCursor(new String[] { "_id", "title" })
  {
     @Override
     public Bundle getExtras() {
        return new Bundle();
     }
  };
Wirling
  • 4,810
  • 3
  • 48
  • 78