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. jQuery提供的Ajax方法

    jQuery提供了4个ajax方法:$.get()  $.post()  $.ajax()  $.getJSON() 1.$.get() $.get(var1,var2,var3,var4): 参数1 ...

  2. Centos7安装后进不去,死活就要填licence,该怎么办?

    遇到这个问题不要麻爪,跟着我做: 1 回车 2 回车 c 回车 c 回车 然后就进入系统了. 要使它联网,点右上角的开关按钮,将PCI Ethernet选择为connect状态. 我的centos7是 ...

  3. python模块hashlib、xlwt、pymysql

    一.xlwt xlwt是python第三方模块,主要是对excel的写操作.xlwt使用时必须先安装. 1.安装 在操作系统的cmd窗口输入pip install xlwt回车即可在线安装. 安装完成 ...

  4. Lambda表达式看这篇基本就够用了

    本文讯] 2020.05.08  polo  写博不易,尊重知识! Lambda  是java8 引入的一个新特性,闭包,又叫函数式接口,下面介绍下,常用的lambda表达式方式: 所谓的将函数作为一 ...

  5. 第0课 - 搭建开发环境之安装QT

    第0课 - 搭建开发环境之安装Qt 1. 课程学习的原材料 — Visual Studio 2010 — Qt SDK 4.7.4 — Qt Creator 2.4.1 2. Visual Studi ...

  6. Spring源码解析 | 第一篇 :IntelliJ IDEA2019.3编译Spring5.3.x源码

    前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这样方便我们在本地环境添加注释.断点追踪.查看类或接口的继承关系等等,更加高效的学习Spring源码.个 ...

  7. spring mvc(4) HandlerMapping

    在前面一节里提到,DispatcherServlet在接收到请求后,通过HandlerMapping找到处理请求对应的Controller(其实处理请求器并不一定是Controller,还可以是Htt ...

  8. BeautifulSoup解析页面

    beautiful soup是一个解析包,专门用来解析html语法的,lxml是一个解析器,用来分析以及定位内容的 .是class #是id import requests from bs4 impo ...

  9. 常用JVM 启动参数解析

    https://www.jianshu.com/p/a17dcef57559 https://www.cnblogs.com/zkyefei/p/9334562.html

  10. Bulldog1靶机渗透

    Bulldog1靶机渗透 扫描一下内网存活主机,发现192.168.114.144这个存活主机. 进行端口扫描:23,80,8080端口均开放. 进行网页访问,暂时没有什么发现,扫一下网站的目录. 发 ...