tv =(TextView) findViewById(R.id.tv);
registerForContextMenu(tv); //给该控件注册上下文菜单
}
@Override
public voidonCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfomenuInfo) {
super.onCreateContextMenu(menu,v, menuInfo);
menu.setHeaderIcon(R.drawable.ic_launcher);
menu.setHeaderTitle("提示操作");
menu.add(1,1,10,"添加");
menu.add(1,2,9,"修改");
menu.add(2, 3, 8, "删除");
}
@Override
public booleanonContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Toast.makeText(this,"添加", Toast.LENGTH_LONG).show(); break;
case 2:
Toast.makeText(this,"修改", Toast.LENGTH_LONG).show(); break;
case 3:
Toast.makeText(this,"删除", Toast.LENGTH_LONG).show(); break;
}
returnsuper.onContextItemSelected(item);
}
}