从硬编码数组而不是DB创建游标 [英] Create a cursor from hardcoded array instead of DB

查看:116
本文介绍了从硬编码数组而不是DB创建游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个正在写的小游戏应用程式建立拖曳清单。

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

清单中有6个项目。然而,我添加的库需要一个Cursor对象与数据库。这是对我的情况overkill。

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.

有没有办法创建一个Cursor对象,基于内存的数据结构,如数组?是否有一种方法可以使用硬编码的数组作为我的Cursor?

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?

谢谢

推荐答案

查看 MatrixCursor 文档。请检查此示例

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

这篇关于从硬编码数组而不是DB创建游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆