Android 小项目之SQLite 使用法门
2010-06-13 15:25:00 来源:WEB开发网protected final static int MENU_EDIT=Menu.FIRST+1;
protected final static int MENU_DELETE=Menu.FIRST+2;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
menu.add(Menu.NONE, MENU_ADD, 0, R.string.ADD);
menu.add(Menu.NONE, MENU_EDIT, 0,R.string.EDIT);
menu.add(Menu.NONE, MENU_DELETE, 0,R.string.DELETE);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case MENU_ADD:
operation("add");
break;
case MENU_EDIT:
operation("edit");
break;
case MENU_DELETE:
operation("delete");
break;
default:
break;
}
return true;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myEditText=(EditText)findViewById(R.id.EditText1);
myListView=(ListView)findViewById(R.id.ListView1);
db=new dbHelper(testDbActivity.this);
myCursor=db.select();
SimpleCursorAdapter adpater=new SimpleCursorAdapter(this
, R.layout.test, myCursor,
new String[]{dbHelper.FIELD_TITLE},
new int[]{R.id.topTextView});
myListView.setAdapter(adpater);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
更多精彩
赞助商链接