【发布时间】:2018-02-26 17:37:53
【问题描述】:
我已经为我的数据库和 TextView 构建了代码,但是 (EDITED:) 我不知道 STEPS 如何从我的数据库中检索数据并显示它们在 TextView 中。 一般来说,为了拍照,我会使用数据库中的地图保存另一个活动的位置。这是我的数据库代码:
class MyDatabaseHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "MapLocations.db";
private static final String TABLE_LOCATIONS = "Locations";
private static final String COLUMN_ID = "_id";
private static final String COLUMN_LOCATIONNAME = "LocationName";
MyDatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_LOCATIONS + "(" + COLUMN_ID +
" INTEGER PRIMARY KEY AUTOINCREMENT, " + COLUMN_LOCATIONNAME +
" TEXT" + ");";
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE " + TABLE_LOCATIONS);
onCreate(db);
}
void addLocation(String string) {
ContentValues values = new ContentValues();
values.put(COLUMN_LOCATIONNAME, string);
getWritableDatabase().insert(TABLE_LOCATIONS, null, values);
}
}
这是我在 TextView 中的活动:
public class PreviousLocationsActivity extends AppCompatActivity {
TextView textv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_previous_locations);
textv = (TextView) findViewById(R.id.dbtextv);
(????)
}
我知道这很简单,但我需要一点帮助。 我只想检索和显示我的数据库在 TextView 中可能拥有的任何数据。 我怎样才能做到这一点?
【问题讨论】:
-
您对哪一部分有问题?您是否在查询数据库、将响应转换为文本或设置 textview 的文本时遇到问题?
-
this solution 可能会有帮助
-
错误是你要代码,这意味着你在做你的工作而不是你。只有您应该编写代码。我们可以帮助您编写它,但不能代替您编写。因此,如果您需要帮助,请向
Take data from my database说明具体是什么问题?为什么你做不到? -
我需要步骤对不起步骤或程序来做这个代码是好的。
-
你的问题有问题的是你要求完整的代码,并且似乎拒绝阅读如何自己解决这个问题的教程。