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() ...
随机推荐
- ASP调用WEBSERVICE并对返回结果进行解析时遇到的问题
项目上用动易平台做新闻发布网站,动易平台是用ASP做的,期间需要根据当前登录的用户,取其他系统比如OA的待办事项进行列表展示,OA组的同事给了我一个WSDL接口,百度了很多ASP调用webservic ...
- 一文带你了解Sql优化
我们后台开发人员每天都难免与数据库打交道,那么你在写sql语句的时候有注重到自己sql的效率吗?当你sql查询速度很慢的时候你有想过是你的sql语句造成的吗?看完这篇文章,我相信你会对sql优化有了一 ...
- [LeetCode]364. 加权嵌套序列和 II (DFS)
题目 给一个嵌套整数序列,请你返回每个数字在序列中的加权和,它们的权重由它们的深度决定. 序列中的每一个元素要么是一个整数,要么是一个序列(这个序列中的每个元素也同样是整数或序列). 与 前一个问题 ...
- goto 语法在 PHP 中的使用
在C++.Java及很多语言中,都存在着一个神奇的语法,就是goto.顾名思义,它的使用是直接去到某个地方.从代码的角度来说,也就是直接跳转到指定的地方.PHP中也有这个功能,我们先来看看它是如何使用 ...
- 【译】Visual Studio 2019 的 Local Process with Kubernetes
今天,我们自豪地宣布 Local Process with Kubernetes 的预览版已加入到 Visual Studio 2019 16.7 Preview 2 中. Local Proces ...
- Typora基础使用
Markdown学习 标题 三级标题 四级标题 字体 Hello,World! Hello,World! Hello,World! Hello,World! 引用 选择狂神说Java,走向人生巅峰 分 ...
- 规则引擎在IoT的重要性?
前言 物联网的强大功能主要来自于它使我们能够实时做出更准确的决策的能力,这些在通知.自动化和预测性维护上都有所体现.因此我们需要能对实时数据进行实时响应的工具,答案就是规则引擎.规则引擎可以通过摄取实 ...
- Linux实战(17):Linux配置用户登陆时发送邮件到指定邮箱
参考其他文章,正好有这个需求,记一笔做个记录,以防丢失. 参考链接 #!/bin/bash yum install -y mailx cat >> /etc/mail.rc<< ...
- Istio 运维实战系列(2):让人头大的『无头服务』-上
本系列文章将介绍用户从 Spring Cloud,Dubbo 等传统微服务框架迁移到 Istio 服务网格时的一些经验,以及在使用 Istio 过程中可能遇到的一些常见问题的解决方法. 什么是『无头服 ...
- java 多线程-4
十四.sleep方法和wait方法的区别 [面试题] 相同点: 一旦执行方法,都可以使得当前线程进入阻塞状态. 不同点: 两个方法的声明位置不同:Thread类声明sleep():Object类中声明 ...