获取 onCreateContextMenu 中的行位置

发布于 2024-09-24 09:12:02 字数 80 浏览 0 评论 0原文

我正在尝试创建一个上下文菜单,根据单击的行来更改可用选项。

但在创建菜单之前,我无法弄清楚如何获取所单击的行的列表视图中的行位置。

I'm trying to create a context menu that changes the available options depending on which row was clicked.

But I can't figure out how to get the row position in the listview for row that was clicked, until after the menu is created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一片旧的回忆 2024-10-01 09:12:02

一点也不明显,但代码如下:

   public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
   {    
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        int position = info.position;

It is not obvious at all, but here's the code:

   public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
   {    
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        int position = info.position;
离去的眼神 2024-10-01 09:12:02

上述解决方案对我不起作用。这是我使用的:

@Override
    public void onCreateContextMenu(ContextMenu menu, View v,
                                    ContextMenu.ContextMenuInfo menuInfo) {
        menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleEnrolment));
        menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleAfterCare));
        menu.add(0, v.getId(), 0, context.getString(R.string.contextMenuDelete));

        pos = getPosition();
    }

The above solution did not work for me. Here is what I used:

@Override
    public void onCreateContextMenu(ContextMenu menu, View v,
                                    ContextMenu.ContextMenuInfo menuInfo) {
        menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleEnrolment));
        menu.add(0, v.getId(), 0, context.getString(R.string.tabTitleAfterCare));
        menu.add(0, v.getId(), 0, context.getString(R.string.contextMenuDelete));

        pos = getPosition();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文