问题描述
我有一个活动,其中有两个编辑文本字段:一个用于标题,另一个用于故事.
由两个文本字段组成的条目将保存在数据库中,该数据库还具有 ROW_ID
, TITLE_ID
和 STORY_ID
.这些条目显示在列表视图中.
长按一个项目后,我得到对应于该项目的行ID .
我应该如何从中获取 TITLE_ID
和 STORY_ID
?
I have an activity which has two edit text fields: one for the title and the other for the story.
The entries made two text fields are saved in the database, also the database has a ROW_ID
,TITLE_ID
and STORY_ID
. The entries are displayed in a list view.
When an item is long clicked, I get the row id corresponding to that item.
How should I get the TITLE_ID
and STORY_ID
from this?
推荐答案
说,您已经在变量 rid 中长按了该项目的相应行ID.然后运行以下查询:
Say, you have the corresponing row id of item which is long clicked in a variable rid. Then run the following query:
String q = "SELECT * FROM TABLE_NAME where(ROW_ID like '"+rid+"')";
Cursor c = db.rawQuery(q, null); // db is a object of SQLiteDatabase type
然后检索 TITLE_ID 和 STORY_ID ,例如:
if(c.getCount() == 0)
{
//No entry found
}
else {
c.moveToFirst();
do {
String titleid = c.getString(c.getColumnIndex("TITLE_ID"));
String storyid = c.getString(c.getColumnIndex("STORY_ID"));
} while (c.moveToNext());
c.close();
然后随便使用它们:)
Then use them as you like :)
这篇关于需要Android数据库帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!