【发布时间】:2011-12-30 19:37:32
【问题描述】:
我有两个表格,我想使用列表 Activity 在列表视图中显示这两个表格的一部分。但只有一张表显示。我有一个外键集,但除了显示一个表之外什么都没有。
我的表格
db.execSQL("CREATE TABLE " + WW_TABLE +
" (" + KEY_ROWIDLL + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_LAT + " TEXT NOT NULL, " +
KEY_LON + " TEXT NOT NULL);");
db.execSQL("CREATE TABLE " + WW_TIMETABLE +
" (" + KEY_ROWIDTIME + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_HOUR + " TEXT NOT NULL, " +
KEY_FOREIGN + " INTEGER," +
" FOREIGN KEY ("+KEY_FOREIGN+") REFERENCES "+WW_TABLE+" ("+KEY_ROWIDLL+") ON DELETE CASCADE);");
我如何查询信息
public Cursor fetchTime() {
// TODO Auto-generated method stub
return ourdb.query(WW_TIMETABLE, new String[] {KEY_ROWIDTIME, KEY_HOUR, KEY_FOREIGN}, null, null, null, null, null);
}
我在哪里查看信息
private void fillData() {
// Get all of the rows from the database and create the item list
mTimeNotesCursor = mDbHelper.fetchTime();
startManagingCursor(mTimeNotesCursor);
// startManagingCursor(mNotesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{WWDatabase.KEY_HOUR,WWDatabase.KEY_FOREIGN};
//String[] fromTime = new String[]{WWDatabase.KEY_HOUR};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.textView2, R.id.textView3};
//int[] toTime = new int[]{R.id.textView4};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.time_text_row, mTimeNotesCursor, from, to);
setListAdapter(notes);
// SimpleCursorAdapter notesTime =
//new SimpleCursorAdapter(this, R.layout.time_text_row, mTimeNotesCursor, fromTime, toTime);
//setListAdapter(notesTime);
}
我没有得到任何错误,但就像我说的那样,它只显示一个表。感谢所有帮助。
【问题讨论】:
-
请查看 [其他问题][1] 以获得帮助。 [1]:stackoverflow.com/questions/8731603/…