これはおそらく単純な答えのばかげた質問ですが、メモ帳の例から単純なカーソルアダプターを使用すると、データベースから名前のリストを取得します。
行の上にカーソルを移動して名前を抽出することで「手動」で実行しようとすると、カーソルは行がゼロであると表示します...
これは例のように機能します。
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only NAME)
String[] from = new String[]{WeightsDatabase.KEY_NAME};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.weightrows};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.weights_row, notesCursor, from, to);
setListAdapter(notes);
今私はこれをやろうとしていますが、それは完全には機能していません。単純なカーソルアダプタは、私がしていない特別なことをしていますか?
//check # of rows, returns 0
int mOne = notesCursor.getCount();
//initial random string array
String[] temp = new String[100];
int i = 0;
notesCursor.moveToFirst();
do{
temp[i]=notesCursor.getString(notesCursor.getColumnIndex(WeightsDatabase.KEY_ROWID)); //crashes here
//index out of bounds
i++;
}while(notesCursor.moveToNext());
私はこれを機能させましたが、「 _ 」という名前のすべての行を返すなどの特定のクエリを返します。すべてのメモを返すことの違いは何ですか?