我正在尝试使用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);
}
答案 0 :(得分:1)
您可以扩展Adapter并覆盖bindView方法,或调用setViewBinder。这里有几个详细的解决方案,这里有一个类似的问题:
Android: Binding data from a database to a CheckBox in a ListView?