我在列表视图中显示我的数据库中的记录时遇到问题。这是我的代码
public class FirstTab extends ListActivity {
private DatabaseHelper dbhelper;
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.first);
dbhelper = new DatabaseHelper(getApplicationContext());
Cursor cursor = dbhelper.getAllNotes();
startManagingCursor(cursor);
String[] columns = new String[] {DatabaseHelper.colTitle , DatabaseHelper.colDate};
int[] to = new int[] { android.R.id.text1, android.R.id.text2};
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, columns, to);
setListAdapter(mAdapter);
}
}
和
...
public Cursor getAllNotes()
{
SQLiteDatabase db=this.getReadableDatabase();
return db.query(noteTable, new String [] {colTitle, colDesc, colDate}, null, null, null, null, null);
}
...
如果你需要更多,这里是回购https://github.com/grzegorz-l/myHomeworks
当我启动我的应用程序时,它在开始时崩溃(RuntimeException)。如果我在 onCreate 方法中注释最后 2 行,它会运行,但 ofc 不显示任何内容。
提前致谢
格雷格