android 长按菜单的使用

//在创建时注册
registerForContextMenu(ctrList);



/**************
*生成长按菜单
*************
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
if(v.getId()==R.id.list_Importing)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.black_list_context_menu_imporiting, menu);
}else
{
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.black_list_context_menu, menu);
menu.setHeaderTitle(mList.get(info.position).num);
}
super.onCreateContextMenu(menu, v, menuInfo);
}

//处理菜单事件
public boolean onContextItemSelected(MenuItem item) {
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
// info.position
switch (item.getItemId()) {
case R.id.menu_item_delete_this:
break;
case R.id.menu_item_delete_all:
break;
}
return super.onContextItemSelected(item); 
}
posted @ 2011-11-03 11:29  meieiem  阅读(4249)  评论(0编辑  收藏  举报