views:

804

answers:

1

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) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.questions);


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

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

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


            setListAdapter(results);
  }
+1  A: 

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:

http://stackoverflow.com/questions/1505751/android-binding-data-from-a-database-to-a-checkbox-in-a-listview

Jeff Gilfelt
That worked perfectly, thanks.
manicmethod