1 给不同控件注册上下文菜单添加不同的布局
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if(v instanceof ListView){
//添加ListView的上下文菜单
}else if(v instanceof Button){
//添加Bu
tton的上下文
菜单
}
2 ListView注册上下文菜单,获取item的位置
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info=(AdapterContextMenuInfo)
item.getMenuInfo();
int p=info.position;