Create a cursor from hardcoded array instead of DB
https://stackoverflow.com/questions/18290864/create-a-cursor-from-hardcoded-array-instead-of-db
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
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);
- ,@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
- 2It 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
maybe you can check MatrixCursor class that you can call addRow((Iterable<?> columnValues) or addRow(Object[] columnValues) hope that will help
use MatrixCursor, instead of addRow() which is not very handy, use builder method newRow()
Create a cursor from hardcoded array instead of DB的更多相关文章
- How To Create SharePoint 2010 Site Collection In Its Own DB
在SharePoint 2010中可以使用Management Shell 为新建的Site Collection 创建自己的DB. 在 Shell中执行如下命令: 1. $w = get-spweb ...
- create feature from text file
'''---------------------------------------------------------------------------------- Tool Name: Cre ...
- 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 ...
- OpenGL.Vertex Array Object (VAO).
OpenGL抛弃glEnable(),glColor(),glVertex(),glEnable()这一套流程的函数和管线以后,就需要一种新的方法来传递数据到Graphics Card来渲染几何体,我 ...
- python插入记录后取得主键id的方法(cursor.lastrowid和conn.insert_id())
#!/usr/bin/python # import MySQL module import MySQLdb # get user input name = raw_input("Pleas ...
- 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 ...
- 14.Iterate a Cursor in the mongo Shell-官方文档摘录
1 迭代游标 } ); while (myCursor.hasNext()) { print(tojson(myCursor.next())); } } ); myCursor.forEach(pri ...
- OpenGL.Vertex Array Object (VAO) [转]
http://www.cppblog.com/init/archive/2012/02/21/166098.html 一 OpenGL抛弃glEnable(),glColor(),glVertex() ...
- OpenGL.Vertex Array Object (VAO) 【转】
http://www.cppblog.com/init/archive/2012/02/21/166098.html 一 OpenGL抛弃glEnable(),glColor(),glVertex() ...
随机推荐
- java初探(1)之登录总结
登录总结 前几章总结了登录各个步骤中遇到的问题,现在完成的做一个登录的案例,其难点不在于实现功能,而在于抽象各种功能模块,提高复用性,较低耦合度. 前端页面: 对于前端页面来说,不是后端程序员要考虑的 ...
- CTF常见源码泄漏总结
.hg源码泄漏 漏洞成因: hg init的时候会生成.hge.g.http://www.am0s.com/.hg/ 漏洞利用:工具:dvcs-ripperrip-hg.pl -v -u http:/ ...
- 小程序开发-Map地图组件
Map组件 是原生组件,使用时请注意相关限制.个性化地图能力可在小程序后台"设置-开发者工具-腾讯位置服务"申请开通. 设置subkey后,小程序内的地图组件均会使用该底图效果,底 ...
- openshift搭建私有registry
1.创建registry服务器 (1)安装需要的包 yum -y install podman httpd-tools (2)创建registry目录 mkdir -p /opt/registry/{ ...
- 剑指 Offer 55 - I. 二叉树的深度
题目描述 输入一棵二叉树的根节点,求该树的深度.从根节点到叶节点依次经过的节点(含根.叶节点)形成树的一条路径,最长路径的长度为树的深度. 例如: 给定二叉树 [3,9,20,null,null,15 ...
- Vue指令之条件渲染
1. v-show 根据表达式的真假值,切换元素的 display CSS属性.表达式为false时,p标签被赋予 style="display:none;" <p v-sh ...
- Java代码工具EasyCode使用
写Java代码,增删改查,最无趣而又最基础.那机器人就来了,帮你写,减少你的基础的无趣的工作. 推荐两个代写代码的神奇工具Mybatis-generator与EasyCode.这两款软件的数据库持久层 ...
- Django启动框架自带原始页面(Django一)
1.安装,cmd中输入命令: pip install django (前提是python已安装完成,才可以使用pip这个python的库管理工具)ps:在cmd中使用pip命令安装时可能因为速度过慢而 ...
- JS红宝书笔记——第一章 JavaScript简介
1.JavaScript简史 Netscape公司决定开发一种客户端语言用来处理浏览器端简单的表单验证. Netscape公司派布兰登·艾奇(BrendanEich)为计划于1995年2月发布的Net ...
- JS将数字转换为中文
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...