游标适配器中的 IF 语句?
private void datafill()
{
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
/* JournalRowId is the row id from the first database containing all journal names
All notes are kept in database 2. I want only the notes that correspond to each
journal to be listed, KEY_HOMEID is the non visible field that shows where
each note came from.
*
*/
if (editjournalDbAdapter.KEY_HOMEID == journalRowId){
String[] from = new String[]{editjournalDbAdapter.KEY_HEIGHT};
int[] to = new int[]{R.id.detail1};
}
//Error here "from" and "to" are not defined outside of if statement
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.journaldetailrow, notesCursor, from, to);
setListAdapter(notes);
}
private void datafill()
{
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
/* JournalRowId is the row id from the first database containing all journal names
All notes are kept in database 2. I want only the notes that correspond to each
journal to be listed, KEY_HOMEID is the non visible field that shows where
each note came from.
*
*/
if (editjournalDbAdapter.KEY_HOMEID == journalRowId){
String[] from = new String[]{editjournalDbAdapter.KEY_HEIGHT};
int[] to = new int[]{R.id.detail1};
}
//Error here "from" and "to" are not defined outside of if statement
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.journaldetailrow, notesCursor, from, to);
setListAdapter(notes);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“from”和“to”仅存在于 if() 语句的范围内。无论如何,否则没有多大意义 - 即使它们这样做,它们的内容也将是未定义的(或者,对于 Java,为 null)并立即使您的应用程序崩溃。
我不知道您想要完成什么,但您可能还希望 if() 块内有底部的两个语句。
"from" and "to" only exist within the scope of the if() statement. Wouldn't make much sense otherwise anyway - even if they did, their contents would be undefined (or, in case of Java, null) and immediately crash your app.
I have no idea what you're trying to accomplish, but you probably want the bottom two statements inside the if() block as well.