Create a cursor from hardcoded array instead of DB

空扰寡人 提交于 2019-11-30 07:02:44

问题


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


回答1:


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



回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/18290864/create-a-cursor-from-hardcoded-array-instead-of-db

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!