Java – ListActivity with checkbox in Android


I am trying to use ListActivity and a SimpleCursorAdapter to check boxes based on a query from a database. The cursor is a list of questions and answers. If the user has already answered a question the checkbox should be checked but they aren't checked. The code looks like this:

protected void onCreate(Bundle savedInstanceState) {

    Cursor c;
    testDbAdapter db = new testDbAdapter(this);
    c = db.getQuestions(Long.toString(mRowId), Integer.toString(mSection));

            String[] from = new String[]{testDbAdapter.QUESTIONS_Q, testDbAdapter.QUESTIONS_A};
            int[] to = new int[]{,};

            SimpleCursorAdapter results = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, c, from, to);


Best Solution

You can extend the Adapter and override the bindView method, or call setViewBinder. A couple of detailed solutions to this are answered in a similar question here:

Android: Binding data from a database to a CheckBox in a ListView?