How to insert extra elements into a SimpleCursorAdapter or Cursor for a Spinner?

后端 未结 4 1950
借酒劲吻你
借酒劲吻你 2020-12-04 14:57

I have a Spinner which is to show a list of data fetched from database. The data is returned to a cursor from query, and the cursor gets passed to spinner\'s SimpleCursorAda

4条回答
  •  长情又很酷
    2020-12-04 15:28

    You can use a combination of MergeCursor and MatrixCursor with your DB cursor like this:

    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);
    

提交回复
热议问题