问题描述
我已经创建了pre-填充SQLite数据库(使用SQLite浏览器)的Android应用程序。将文件复制到我的手机上的/数据路径完美地工作,但我似乎无法让我的头周围的东西。
I've created an Android app with a pre-populated SQLite database(using SQLite Browser). Copying the file to the /data path on my phone worked perfectly, but I can't seem to get my head around something.
我需要从一个给定的ID获得连胜,在TextViews设置此结果,并当另一个ID被赋予更新的新结果TextViews。这ofcourse应该是很容易的,所以我读过一切从教程在Android开发工地等信息。出于某种原因,我只是似乎没有得到这个。有人可以帮助我开始使用这个或链接我的一些资源来解释这种情况particulair?
I need to get a row from a given ID, set this result in TextViews and when another ID is given update the TextViews with the new result. This ofcourse should be quite easy, so I've read everything from tutorials to information on the Android dev site and SO. For some reason I just don't seem to get this. Can someone help me get started with this or link me to some resource that explains this particulair situation?
感谢您。
推荐答案
使用游标从数据库中获取数据
Use Cursor to get data from the database
Database db = new Database(this);
Cursor yourdata = db.getDetails(this);
if(yourdata!=null)
{
yourdata.moveToFirst();
String value= cursor.getString(cursor.getColumnIndex(databaseColumn);
TextView youtextview = (TextView) findViewById(R.id.textview);
youtextview .setText(value);
}
在数据库类创建getDetails()方法。
Create getDetails() method in Database Class.
public Cursor getDetails(Activity youactivity,
int projectid) {
SQLiteDatabase db = getReadableDatabase();
String from[] = { YourColumn};
String where = ID+"="+projectid;
Cursor cursor = db.query(true, Table, from, where, null, null, null, null, null);
return cursor;
}
希望它能帮助
这篇关于通过ID返回一行在SQL查询精简版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!