Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a cursor from hardcoded array instead of DB

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

like image 638
ddoor Avatar asked Aug 17 '13 16:08

ddoor


3 Answers

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);
like image 133
Trinimon Avatar answered Nov 08 '22 14:11

Trinimon


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

like image 2
Moh Sakkijha Avatar answered Nov 08 '22 14:11

Moh Sakkijha


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

like image 1
pskink Avatar answered Nov 08 '22 12:11

pskink