SimpleAdapter需要一个_id领域 [英] SimpleAdapter needs an _id field

查看:126
本文介绍了SimpleAdapter需要一个_id领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个:

光标C = db.query(组织,NULL,NULL,NULL,NULL,NULL,NULL);

这意味着我选择一表组织,但与此一并我需要这样的:

which means I choose a table "Org", but together with this I need to make this :

 Cursor c = db.rawQuery(" SELECT "+ id + " AS _id")

由于SimpleAdapter需要有一个 _id 字段不一定出于某种原因,否则将有一个错误崩溃。我如何结合成一个查询这2?

because SimpleAdapter need to have an _id field necessarily for some reason or it will crash with an error. How do I combine this 2 into one query?

推荐答案

有关您的语句:光标C = db.query(组织,NULL,NULL,NULL,NULL,NULL,NULL) ; 第二个参数是错误的,你shoukd提列名在其

For your statement : Cursor c = db.query("Org", null, null, null, null, null, null); the second parameter is wrong, you shoukd mention the column names in it.

public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

而对于,

Cursor c = db.rawQuery(" SELECT "+ id + " AS _id from Org"); 

意味着你选择 ID 并使用创建它的别名 _id ,而你选择这个 ID 单位表。
所以现在你就可以从该查询从列名 _id ,访问结果,并以访问结果使用:

means that you Select id and create an alias of it using AS into _id, and you are selecting this id from Org table. so now you will be able to access the result from this query from the column name _id, and in order to access the result use:

c.moveToFirst();    
while (c.moveToNext())
{
 System.out.println(c.getString(c.getColumnIndex("_id")); 
}

这篇关于SimpleAdapter需要一个_id领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆