游标适配器中的 IF 语句?

发布于 2024-09-10 06:35:00 字数 901 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伴随着你 2024-09-17 06:35:00

“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文