下面这个例子:数据存在数据库中
//响应上下文菜单
public boolean onContextItemSelected(MenuItem item)
{
// // 得到当前被选中的item信息
AdapterContextMenuInfo infor = (AdapterContextMenuInfo)item.getMenuInfo();
int id=infor.position;
myCursor.moveToPosition(id);
_id=myCursor.getInt(0);
// au.setText(myCursor.getString(2));
System.out.println(myCursor.getString(2));
String myname=myCursor.getString(2);
showlist();
switch (item.getItemId())
{
case R.id.c2: //编辑
//跳转到编辑界面
Intent bintent = new Intent(MainActivity.this,UpdateActivity.class);
bintent.putExtra("na", myname);
startActivityForResult(bintent, 11);
if(flog==1)
{
System.out.println("*****************");
db.update(_id,U);//更新数据库中的数据
}
showlist();
break;
case R.id.c3: //删除
db.delete(_id);
showlist();
break;
default:
return super.onContextItemSelected(item);
}
_id=0;
return true;
}