43

I am trying to make a drag-and-drop list for a little game app I am writing.

There are 6 entries in the list. However the library I added required a Cursor object that talks to a DB. This is overkill for my situation.

Is there a way to create a Cursor object that is based on a memory-based data structure like an array? Is there a way I can used a hard-coded array as my Cursor?

Thanks

General Grievance
  • 4,555
  • 31
  • 31
  • 45
ddoor
  • 5,819
  • 9
  • 34
  • 41

3 Answers3

55

Check out the MatrixCursor documentation. Check for instance this example.

String[] columns = new String[] { "_id", "item", "description" };

MatrixCursor matrixCursor= new MatrixCursor(columns);
startManagingCursor(matrixCursor);

matrixCursor.addRow(new Object[] { 1, "Item A", "...." });

SimpleCursorAdapter adapter = 
        new SimpleCursorAdapter(this, R.layout.layout_row, matrixCursor, ...);

setListAdapter(adapter);
Community
  • 1
  • 1
Trinimon
  • 13,839
  • 9
  • 44
  • 60
  • ,@FaddishWorm Thanks for the post. Would you kindly tell me why am I getting "return type for the method is missing" error for startManagingCursor(matrixCursor). What what the solution to fix this. I am using API 19 with minimum api support 8. – Dexter Jun 01 '14 at 06:18
  • @FaddishWorm: I solved the issue.It was a silly mistake. I was doing the call at the wrong place ie. not inside any method of the class. I managed to work it as getActivity().startManagingCursor(matrixCursor) as the class is a Fragment. – Dexter Jun 01 '14 at 06:31
  • 2
    It would be nice for complete code. IE that layout is something you made??? I'm just testing libraries here and I need a cursor with strings – StarWind0 Oct 16 '15 at 11:24
2

maybe you can check MatrixCursor class that you can call addRow((Iterable<?> columnValues) or addRow(Object[] columnValues) hope that will help

Moh Sakkijha
  • 2,705
  • 1
  • 14
  • 19
1

use MatrixCursor, instead of addRow() which is not very handy, use builder method newRow()

pskink
  • 23,874
  • 6
  • 66
  • 77