我有这段代码,这是一个列表类,我将在这里保存我的笔记,但是每当我打开这个类时,它一直告诉我强制关闭它。
知道为什么吗?
public class Class1 extends ListActivity {
private static final int ACTIVITY_CREATE1=0;
private static final int ACTIVITY_EDIT1=1;
private static final int DELETE_ID1 = Menu.FIRST;
private int mNoteNumber1 = 1;
private Class1Db mDbHelper1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.class1);
mDbHelper1 = new Class1Db (this);
mDbHelper1.open();
fillData();
registerForContextMenu(getListView());
Button addnote = (Button)findViewById(R.id.addnotebutton);
addnote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createNote();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.class1, menu);
return true;
}
private void createNote() {
Intent i = new Intent(this, DeleteEdit1.class);
startActivityForResult(i, ACTIVITY_CREATE1);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent i = new Intent(this, DeleteEdit1.class);
i.putExtra(Class1Db.KEY_ROWID1, id);
startActivityForResult(i, ACTIVITY_EDIT1);
}
private void fillData() {
// Get all of the notes from the database and create the item list
Cursor notesCursor = mDbHelper1.fetchAllNotes();
startManagingCursor(notesCursor);
String[] from = new String[] { Class1Db.KEY_TITLE1 ,Class1Db.KEY_DATE1};
int[] to = new int[] { R.id.text1 ,R.id.date_row};
// Now create an array adapter and set it to display using our row
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.class1row, notesCursor, from, to);
setListAdapter(notes);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID1, 0, R.string.menu_delete);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case DELETE_ID1:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper1.deleteNote(info.id);
fillData();
return true;
}
return super.onContextItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
fillData();
}
}