Android Dialog中的listview创建上下文菜单
listView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(0, 0, 0, "天天"); menu.add(0, 1, 0, "人人"); menu.getItem(0).setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem clickedItem) { Toast.makeText(BaseMap.this, "用户点击了菜单", 1500) .show(); return true; } }); menu.getItem(1).setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem clickedItem) { Toast.makeText(BaseMap.this, "用户点击了菜单", 1500) .show(); return true; } }); } });
这种情况下调用onContextItemSelected方法无事件响应,上面用法已验证可行。