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

Asked 6 years, 11 months ago
Viewed 18k times
 
41

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

 
asked Aug 17 '13 at 16:15
FaddishWorm

5,03899 gold badges2929 silver badges4141 bronze badges

3 Answers

 
53
 

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);
 
answered Aug 17 '13 at 16:21
Trinimon

13.1k99 gold badges3838 silver badges5858 bronze badges
  •  
    ,@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 1 '14 at 6: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 1 '14 at 6: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

 
answered Aug 17 '13 at 16:20
Moh Sakkijha

2,62511 gold badge1111 silver badges1919 bronze badges
 
1

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

 
answered Aug 17 '13 at 16:37
pskink

19.8k66 gold badges4646 silver badges6565 bronze badges

add a comment

Create a cursor from hardcoded array instead of DB的更多相关文章

  1. How To Create SharePoint 2010 Site Collection In Its Own DB

    在SharePoint 2010中可以使用Management Shell 为新建的Site Collection 创建自己的DB. 在 Shell中执行如下命令: 1. $w = get-spweb ...

  2. create feature from text file

    '''---------------------------------------------------------------------------------- Tool Name: Cre ...

  3. Multidimensional Array And an Array of Arrays

    One is an array of arrays, and one is a 2d array. The former can be jagged, the latter is uniform. T ...

  4. OpenGL.Vertex Array Object (VAO).

    OpenGL抛弃glEnable(),glColor(),glVertex(),glEnable()这一套流程的函数和管线以后,就需要一种新的方法来传递数据到Graphics Card来渲染几何体,我 ...

  5. python插入记录后取得主键id的方法(cursor.lastrowid和conn.insert_id())

    #!/usr/bin/python # import MySQL module import MySQLdb # get user input name = raw_input("Pleas ...

  6. MongoDB - MongoDB CRUD Operations, Query Documents, Iterate a Cursor in the mongo Shell

    The db.collection.find() method returns a cursor. To access the documents, you need to iterate the c ...

  7. 14.Iterate a Cursor in the mongo Shell-官方文档摘录

    1 迭代游标 } ); while (myCursor.hasNext()) { print(tojson(myCursor.next())); } } ); myCursor.forEach(pri ...

  8. OpenGL.Vertex Array Object (VAO) [转]

    http://www.cppblog.com/init/archive/2012/02/21/166098.html 一 OpenGL抛弃glEnable(),glColor(),glVertex() ...

  9. OpenGL.Vertex Array Object (VAO) 【转】

    http://www.cppblog.com/init/archive/2012/02/21/166098.html 一 OpenGL抛弃glEnable(),glColor(),glVertex() ...

随机推荐

  1. 【小白学PyTorch】7 最新版本torchvision.transforms常用API翻译与讲解

    文章来自:微信公众号[机器学习炼丹术].欢迎关注支持原创 也欢迎添加作者微信:cyx645016617. 参考目录: 目录 1 基本函数 1.1 Compose 1.2 RandomChoice 1. ...

  2. 跟着兄弟连系统学习Linux-【day04】

    day04-20200601 p15.链接文件 [ln -s 原文件   连接文件]软连接,所有人都可以操作软连接文件(实际上是取决于原文件的权限),类似于Windows的快捷方式,方便进行管理.软连 ...

  3. 跟着尚硅谷系统学习Docker-【day02】

    day02-20200714   p9.docker阿里云配置   helloword   拉取镜像-运行-   拉取镜像如果从国外网站拉取辉比较慢,所以需要配置阿里云或者网易云得镜像仓库.   首先 ...

  4. WebApi OAuth2身份认证

    一.什么是OAuth OAuth是一个关于授权(Authorization)的开放网络标准,目前的版本是2.0版.注意是Authorization(授权),而不是Authentication(认证). ...

  5. js拖拽原理及简单实现(渣渣自学)

    第一步 首先简单分析下需求吧,我们就是想实现鼠标拖拽带颜色的方块时,让方块停留在鼠标松开的位置,需要计算的就是拖拽前的坐标和拖拽后的坐标,鼠标移动后相对于原位置的偏移量=目标元素的偏移量,根据这个等式 ...

  6. python django 简单接口测试页面

    项目创建订单只能是接口创建的,之前都是用jar包放到jmeter里调用下单,给产品或者运维用不太方便,就想用django写一个带前端界面的下单web程序 项目结构 代码,比较渣 # coding=ut ...

  7. docker中重启某个服务命令

    docker ps------查看正在运行的cotainners docker ps -a --------查看所有的containners docker restart 容器id docker lo ...

  8. StarUML 3.1.0 for Windows 10

    StarUML 3.1.0 for Windows 10 1.下载 StarUML 3.1.0 http://staruml.io/download 2.安装 npm 到官网下载安装 windows版 ...

  9. SVN检出maven项目

    (一)直接单击项目,右键选择configure,选择convert to maven project (二)删除project explorer中的项目,并重新从工作区间导入maven项目.

  10. 利用glog打印日志

    glog出自互联网豪门google,质量有保证,轻量级,入门简单,功能较全,线程安全.有关glog的打印细节本篇文章不再赘述,网上一大堆的资料,参考:glog日志库使用笔记. glog的托管地址:gi ...