我已经在SimpleCursorAdapter上尝试了几乎所有的解决方案,但仍无法找到答案。
我对代码的每一部分都进行了评论,而SimpleCursorAdapter
似乎导致了错误。
我甚至尝试SimpleCursorAdapter androidsupportv4 widget
,但仍然无效。
这是我的oncreate方法()
public class viewHW扩展了Activity {
private DBadapter db;
private SimpleCursorAdapter dataAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.viewhomework);
db = new DBadapter(this);
db.open();
displayListView();
db.close();
}
private void displayListView() {
// TODO Auto-generated method stub
Cursor c = db.getAllRecords();
String[] columns = new String[] {
DBadapter.KEY_ROWID,
DBadapter.KEY_TITLE,
DBadapter.KEY_DUEDATE,
DBadapter.KEY_QUES1,
DBadapter.KEY_QUES2,
DBadapter.KEY_QUES3,
DBadapter.KEY_QUES4,
DBadapter.KEY_QUES5};
int [] to = new int[]{
R.id.id,
R.id.tt,
R.id.dd,
R.id.ques1,
R.id.ques2,
R.id.ques3,
R.id.ques4,
R.id.ques5};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(viewHW.this, R.layout.viewhomeworkinfo,c, columns, to, 1);
ListView myList=(ListView)findViewById(R.id.listView1);
myList.setAdapter(mAdapter);
}