こんにちは、SimpleCursorAdapter を使用して値をリスト アダプターにバインドしようとしています。カーソルは SQLLite データベースから来ています。ただし、カーソルの結果に関係なく (常に少なくとも 1 行あります)、リスト ビューには空のメッセージが表示されます。
私のコードは以下のとおりです。
In Activity : onCreate() によって呼び出されます
private void setupList() {
if(sesionDao == null) {
sesionDao = new SessionDAO(this);
}
Cursor cursor = sesionDao.retrieveAllSessions();
startManagingCursor(cursor);
String[] from = new String[]{Database.SES_SESSION_NAME};
int[] to = new int[]{R.id.sessionNameRow};
SimpleCursorAdapter sessionAdapter = new SimpleCursorAdapter(this, R.layout.session_list_row,cursor, from, to );
setListAdapter(sessionAdapter);
}
カーソルの取得
db = dbHelper.getReadableDatabase();
Cursor c = db.query(Database.SESSIONS_TABLE_NAME, new String[] {
Database.ID_COLUMN, Database.SES_SESSION_NAME }, null,
null, null, null,null);
session_list_row.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:text="" android:id="@+id/sessionNameRow"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
メインレイアウト
<ListView android:id="@android:id/list" android:layout_height="fill_parent" android:layout_width="fill_parent"></ListView>
<TextView android:id="@android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/no_sessions_msg" />