无法显示上下文菜单

时间:2011-02-06 15:07:01

标签: android sqlite contextmenu

这是我的应用程序,你可以看到我列出了数据,有2个列表 每个列表包含2行和1个图像按钮,我想创建一个ContextMenu(我按下每个列表,它将显示一个ContextMenu)

我已经像这样编写了onCreateContextMenu ......

@Override
    public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
            menu.add(0, EDIT_ID, 0, R.string.menu_edit);
        menu.add(0, DELETE_ID, 0, R.string.menu_delete);
    }

@Override
    public boolean onContextItemSelected(MenuItem item){
        switch(item.getItemId()){
        case EDIT_ID:{
            Cursor cc = cursor;
            Intent edit_Im_Sens = new Intent(Im_SensShow.this,Im_SensEdit.class);
            Bundle bundle = new Bundle();
            bundle.putLong("THIMSENSID", thim_sens_id);
            bundle.putLong("IMSENSID", cc.getLong(cc.getColumnIndexOrThrow(DBAdapter.KEY_IM_SENS_ID)));
            bundle.putLong("LANGSID", cc.getLong(cc.getColumnIndexOrThrow(DBAdapter.KEY_LANGS_ID)));
            bundle.putString("IMSENS",cc.getString(cc.getColumnIndexOrThrow(DBAdapter.KEY_IM_SENS)));
            bundle.putString("READING",cc.getString(cc.getColumnIndexOrThrow(DBAdapter.KEY_READING)));
            edit_Im_Sens.putExtras(bundle);
            startActivityForResult(edit_Im_Sens,1);
            //return true;
            break;
            }

但它不起作用,它不显示ContextMenu 请帮帮....

1 个答案:

答案 0 :(得分:0)

您是否注册了上下文菜单的列表视图?

registerForContextMenu(your_list)

// get the list view
ListView list = (ListView)findViewById(R.id.list);

// set adapter before registering the context menu
list.setAdapter(adapter);

// register it for the context menu
registerForContextMenu(list);

http://www.mikeplate.com/show-a-context-menu-for-long-clicks-in-an-android-listview/