Andorid上下文菜单
1。
//注册上下文菜单
registerForContextMenu(this.myconmentlist);
2.
public boolean onContextItemSelected(MenuItem item) {
// TODO Auto-generated method stub
// AdapterContextMenuInfo lm = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case 1://
break;
case 2://
case 3://
break;
}
return super.onContextItemSelected(item);
}
3
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
// TODO Auto-generated method stub
super.onCreateContextMenu(menu, v, menuInfo);
// AdapterContextMenuInfo lm = (AdapterContextMenuInfo) menuInfo;
// if (lm.id != 0 && lm.id != -1) {
menu.setHeaderTitle("功能");
menu.add(1, 1, 1, "回复评论");
menu.add(1, 2, 2, "查看用户资料");
menu.add(1, 3, 3, "查看原动态");
}
// }
4.在Adapter里面添加以下代码可以实现短按弹出上下文菜单
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
openContextMenu(v);
}
});