【发布时间】:2017-05-08 12:47:26
【问题描述】:
我有一个 listView 填充了我的数据库中的数据。我使用 simpleCursorAdapter 来显示值。
我有一张桌子可以添加课程:英语、法语...
在另一个表中,我可以创建已开发的课程(我添加了开始和结束的日期、哪几天、课程的主题)。我必须以 FK 的身份提供课程。
当我添加课程时,我想在我的列表视图中显示每个示例:英语 - 阅读,但它显示 1 - 阅读。因为 1 是我存储在第二张表中的值。
如何将 1 改为英文?
这是我的代码:
Cursor cursor = dbhelper.getAllCours();
String[] from = { "branche_cours", "designation" }; //here 'branche_cours' is the lesson i store as an INT, it's the FK so
int[] to = { R.id.text_branche_cours, R.id.text_designation };
adapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor, from, to, 0);
lvCours.setAdapter(adapter);
adapter.notifyDataSetChanged();
我使用getAllCours()的方法
public Cursor getAllCours()
{
//from here, i retrieve the ID, designation and branche_cours
String Query = ("select ID as _id, date_debut, date_dernier, dixieme_point, " +
"demi_point, description, designation, lundi, mardi, mercredi, jeudi," +
" vendredi, samedi, branche_cours from " + TABLE_COURS);
Open();
Cursor cursor = db.rawQuery(Query, null);
return cursor;
}
如何将该 int 链接到实际值(那么 '1' 怎么能变成 'English')?
【问题讨论】:
-
我还没有找到解决办法..
标签: android sqlite listview foreign-key-relationship