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. 解放生产力:Spring Boot的注解校验

    关于对象入参的校验,我们可能第一个想到的就是在Controller层或者Service层增加很多if else的判断,如: if (user.getPassword() == "" ...

  2. 从String中移除空白字符的多种方式!?

    字符串,是Java中最常用的一个数据类型了.我们在日常开发时候会经常使用字符串做很多的操作.比如字符串的拼接.截断.替换等. 这一篇文章,我们介绍一个比较常见又容易被忽略的一个操作,那就是移除字符串中 ...

  3. 09 promise then

    then() 方法返回一个 Promise 链式调用:then里面回调函数(成功回调和失败回调),凡事这两个回调函数里面抛出错误或者返回一个已经是拒绝状态的 Promise. 那么 then 返回的  ...

  4. jQuery 如何实现 模糊搜索

    如何实现 模糊搜索 当我们浏览网页的时候,通常能看到搜索栏,这大大的提高了我们获取数据的目的性.那如何去实现一个简单的模糊搜索 框呢,以下案例获取能给你一点思路. 以下案例,可以实现当按键按下时,自动 ...

  5. C:获取屏幕输入

    代码: #include "stdafx.h" #include "stdio.h" int _tmain(int argc, _TCHAR* argv[]) ...

  6. PHP生成二维码 endroid/qr-code 扩展包

    目录 1. 引入 endroid/qr-code 扩展包 2. 使用示例 3. 二维码中放入logo,无法识别二维码的问题 1. 引入 endroid/qr-code 扩展包 https://pack ...

  7. 阿里云短信服务验证码封装类 - PHP

    本文记录在ThinkPHP6.0中使用阿里云短信验证码,该封装类不仅仅局限于TP,拿来即用 使用该类之前必须引入 flc/dysms 扩展,该封装类就是基于这个扩展写的 composer requir ...

  8. python基础:多进程、多线程

    一.定义和区别 1.一个任务就是一个进程,进程就是资源的集合.比如打开浏览器,启动一个进程.当一个进程需要干很多事的时候,就需要执行多个子任务,这些子任务就是线程. 2.线程是包含在进程中的,每个进程 ...

  9. Fragment时长统计那些事

    注:本文同步发布于微信公众号:stringwu的互联网杂谈 frament时长统计那些事 页面停留时长作为应用统计的北极星指标里的重要指标之一,统计用户在某个页面的停留时长则变得很重要.而Fragme ...

  10. PicGo软件搭配gitee实现图床

    1.安装PicGo软件,并配置gitee 1.1安装picGo picGo 安装gitee-uploader 插件 官网下载地址如下:最新版本 可以自行选择版本进行下载,这里我选择了最新的版本进行下载 ...