android 长按菜单的使用
16lz
2022-05-26
//在创建时注册
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);
}
更多相关文章
- Mac上Android(安卓)studio环境搭建
- Android(安卓)Studio第三十四期 - git企业级应用命令
- Android获取SDcard目录及创建文件夹;
- android 添加menu 菜单项
- [APP] Android(安卓)开发笔记 001-环境搭建与命令行创建项目
- Android(安卓)sqlite 基础实例
- 编译生成可执行文件(Android(安卓)studio中)并在android设备中执行
- Android(安卓)8.0和8.1通知栏
- Android(安卓)模糊效果实现