Android 选择一条记录并绑定到文本框
这是我的问题Android 选择一条记录并绑定到文本框,android,sqlite,Android,Sqlite,这是我的问题 SELECT * FROM articles WHERE id >1 ORDER BY id ASC LIMIT 1 我的要求很简单。我只想选择一条记录并绑定到TextView。这就是我到目前为止所做的 public Article oneRecord() { SQLiteDatabase db = this.getWritableDatabase(); Cursor c = db.rawQuery("SELECT * FROM articles WHE
SELECT *
FROM articles
WHERE id >1
ORDER BY id ASC
LIMIT 1
我的要求很简单。我只想选择一条记录并绑定到TextView。这就是我到目前为止所做的
public Article oneRecord()
{
SQLiteDatabase db = this.getWritableDatabase();
Cursor c = db.rawQuery("SELECT * FROM articles WHERE id=3;", null);
if(c.moveToFirst()){
Article a= new Article();
a.setId(c.getString(c.getColumnIndex("id")));
a.setImage_url(c.getString(c.getColumnIndex("image_url")));
a.setTitle(c.getString(c.getColumnIndex("title")));
a.setBody(c.getString(c.getColumnIndex("body")));
}
return a;
}
我不确定我是否正确理解了你的问题。然而,没有什么特别的事情要做。从数据库中获取文章后,只需更新TextView即可
Article a = getOneRecordFromDB();
titleView.setText(a.getTitle());
bodyView.setText(a.getBody());
您能告诉我们为什么您尝试的不起作用吗?需要更多的代码。我可以使用适配器或listView绑定到列表。我更新了我的问题请检查我不知道如何绑定到textview绑定到textview是什么意思?