Android游标问题

Ele*_*ec0 2 android cursor

所以我试图将SQLite数据库中的值转换为游标,然后选择一个随机值.我可以像通常在方法中那样使用getString()读取游标,但是在它返回游标后它无法正常工作.我不知道为什么..这是我从数据库中获取光标的方法.它似乎工作正常.

        public Cursor getRandomText(String Rating)
    {

        Cursor cursor = myDatabase.query("Elec0RandTexts", new String[] {"Message"}, "Rating=?", 
                new String[]{Rating}, null, null, null);
        cursor.moveToFirst();

        cursor.close();

        return cursor;

    }
Run Code Online (Sandbox Code Playgroud)

这是我返回后读取光标的代码.

            Cursor result = dbh.getRandomText(Rating);
        result.moveToFirst();

        int RandText = rand.nextInt(result.getCount());

        result.moveToPosition(RandText);
        Toast.makeText(getApplicationContext(), "" + result.getString(RandText), Toast.LENGTH_LONG).show();

        result.close();
Run Code Online (Sandbox Code Playgroud)

我可能犯了一个愚蠢的错误而没有意识到这一点,但我无法弄清楚这一点.

谢谢,

〜Elec0

Vla*_*nov 6

cursor.close(); // in getRandomText()
Run Code Online (Sandbox Code Playgroud)

之后,您无法从光标获取任何数据 - 它已关闭.删除此行.