Android:RecyclerView项目Contextmenu问题 [英] Android: RecyclerView item Contextmenu issue

查看:178
本文介绍了Android:RecyclerView项目Contextmenu问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个RecyclerView,当单击每个项目时,将弹出一个上下文菜单。

I am trying to implement a RecyclerView, that each item when clicked, a context menu will pop up.

我已引用了 问题 有关如何做我想做的事情。

I have referred the answers/comments from this question on how to to do what I wanted.

我的问题是,通过使用getMenuInfo()检索信息,我一直变得空。即,当我从上下文菜单中选择一项时,这就是我得到的内容

My problem is, I keep getting null by using getMenuInfo() to retrieve info. Ie, When I select an item from the context menu, this is what I get


java.lang.NullPointerException:尝试从字段读取空
对象引用上的'long
com.x.lib.RVCoursesContextMenu $ RecyclerContextMenuInfo.id'

java.lang.NullPointerException: Attempt to read from field 'long com.x.lib.RVCoursesContextMenu$RecyclerContextMenuInfo.id' on a null object reference

我的代码与此 answer 非常相似。

My code for this is very similar to this answer .

很长一段时间以来,我一直在寻找解决方案,如果有人可以帮助我,我将非常感激。

I have been looking for a solution for this for a very long time, would really appreciate if someone could help me on this.

推荐答案

public static class ViewHolder extends RecyclerView.ViewHolder {
    Context cxt;

    public ViewHolder(View itemView, int ViewType, Context cnxt) {
        this.cxt = cnxt;
    }
}

这篇关于Android:RecyclerView项目Contextmenu问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆