1

Hi I ma trying to use a SimpleCursorAdapter to bind values to a list adapter. The cursor is comming from the SQLLite database. However regardless of the results in the cursor (It always has atleast one row) the list view displays the empty message.I am pretty new to android and appreciate any help on this.

My code is given below:

In Activity : Called by 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);
}

Retrieving the cursor

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>

Main Layout <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" />

1 Answer 1

2

I Figured out the problem. I was doing the dumb mistake of closing down the connection when the method ends where cursor gets invalid after that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.