我想使用ListActivity和SimpleCursorAdapter查看基于从数据库中查询框。光标的问题和答案的列表。如果用户已经回答的问题的复选框应进行检查,但他们不检查。代码看起来是这样的:

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);
  }
有帮助吗?

解决方案

可以扩展适配器并重写bindView方法,或呼叫setViewBinder。一对夫妇来此详尽的解决方案都回答这里类似的问题:

机器人:从结合数据一个数据库,以一个CheckBox在ListView?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top