繁体   English   中英

Android:ContextMenu不显示

[英]Android: ContextMenu not displaying

在我的应用程序中,我的主布局中有一个ListView。 在相应的活动中,我的onCreate中包含以下内容:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    app = (MyTallyKeeperApplication) getApplication();
    adapter = new TallyItemListAdapter(this, app.getTallyItems());
    setListAdapter(adapter);
    registerForContextMenu(getListView());
}

ListView中的每个项目都是TallyItemView类型的,继承自LinearLayout。 我用来为上下文菜单充气的代码是:

    @Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Log.i(MyTallyKeeperMain.class.getSimpleName(), "onCreateContextMenu");
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.item_menu, menu);
}

从理论上讲,当您长按某个项目时,将显示一个上下文菜单,其中提供了用于编辑或删除该项目的选项。 但是当我长按一个项目时,什么也没显示。 关于如何解决此问题的任何想法?

如果列表中包含可聚焦项(复选框等),则会发生这种情况。在列表行的布局中,将其包含在可聚焦组件中。

android:focusable="false"

尝试做你的super.onCreateContextMenu(menu, v, menuInfo); 最后而不是第一。 这是一个示例项目,显示了上下文菜单与ListView

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM