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. java初探(1)之登录总结

    登录总结 前几章总结了登录各个步骤中遇到的问题,现在完成的做一个登录的案例,其难点不在于实现功能,而在于抽象各种功能模块,提高复用性,较低耦合度. 前端页面: 对于前端页面来说,不是后端程序员要考虑的 ...

  2. CTF常见源码泄漏总结

    .hg源码泄漏 漏洞成因: hg init的时候会生成.hge.g.http://www.am0s.com/.hg/ 漏洞利用:工具:dvcs-ripperrip-hg.pl -v -u http:/ ...

  3. 小程序开发-Map地图组件

    Map组件 是原生组件,使用时请注意相关限制.个性化地图能力可在小程序后台"设置-开发者工具-腾讯位置服务"申请开通. 设置subkey后,小程序内的地图组件均会使用该底图效果,底 ...

  4. openshift搭建私有registry

    1.创建registry服务器 (1)安装需要的包 yum -y install podman httpd-tools (2)创建registry目录 mkdir -p /opt/registry/{ ...

  5. 剑指 Offer 55 - I. 二叉树的深度

    题目描述 输入一棵二叉树的根节点,求该树的深度.从根节点到叶节点依次经过的节点(含根.叶节点)形成树的一条路径,最长路径的长度为树的深度. 例如: 给定二叉树 [3,9,20,null,null,15 ...

  6. Vue指令之条件渲染

    1. v-show 根据表达式的真假值,切换元素的 display CSS属性.表达式为false时,p标签被赋予 style="display:none;" <p v-sh ...

  7. Java代码工具EasyCode使用

    写Java代码,增删改查,最无趣而又最基础.那机器人就来了,帮你写,减少你的基础的无趣的工作. 推荐两个代写代码的神奇工具Mybatis-generator与EasyCode.这两款软件的数据库持久层 ...

  8. Django启动框架自带原始页面(Django一)

    1.安装,cmd中输入命令: pip install django (前提是python已安装完成,才可以使用pip这个python的库管理工具)ps:在cmd中使用pip命令安装时可能因为速度过慢而 ...

  9. JS红宝书笔记——第一章 JavaScript简介

    1.JavaScript简史 Netscape公司决定开发一种客户端语言用来处理浏览器端简单的表单验证. Netscape公司派布兰登·艾奇(BrendanEich)为计划于1995年2月发布的Net ...

  10. JS将数字转换为中文

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...