问题描述
我创建,上面有一个ListView一个简单的对话框。我希望能够访问它的上下文菜单。这里是基本的code我有:
I'm creating a simple dialog with a ListView on it. I want to be able to access a context menu on it.Here's the basic code I've:
<On CreateDialog>
listViewSongs=(ListView) layout.findViewById(R.id.ListView_Songs);
listViewSongs.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, drawingPanel.metronome.getSongNames()));
registerForContextMenu(listViewSongs);
然后,我只需要添加一个简单的项目:
Then I just add a simple item:
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
super.onCreateContextMenu(menu, v, menuInfo);
menu.setHeaderTitle("Sample Context Menu");
menu.add(0, MENU_EDIT_SONG, 0, "Edit");
}
最后,我重写onContextItemSelected:
And finally I override the onContextItemSelected:
@Override
public boolean onContextItemSelected(MenuItem item) {
super.onContextItemSelected(item);
editSong();
return true;
}
所以我的问题是,当我长preSS列表视图我有上下文菜单,但点击它唯一的选择后,它永远不会调用onContextItemSelected :(任何帮助?
So my problem is that when I longpress the listview I got the context menu, but after clicking the only option on it, it never calls onContextItemSelected :(Any help?
PS:我也尝试重写onMenuItemSelected,onOptionsItemSelected,但我得到了相同的结果:\从来没有得到所谓的
PS: I've tried also to override onMenuItemSelected, onOptionsItemSelected, but I got the same result :\ never got called.
推荐答案
我不知道为什么你有什么不工作,但你可以尝试添加一个监听到你的菜单项来代替:setOnMenuItemClickListener.至少这会告诉你,你的上下文菜单项被选中。
I'm not sure why what you have isn't working, but you could try adding a listener to your menuItem instead: setOnMenuItemClickListener. At least that would tell you that your context menu item was being selected.
这篇关于使用Dialog,它带有一个ListView onContextItemSelected从来没有所谓的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!