Android:RecyclerView项目Contextmenu问题

编程入门 行业动态 更新时间:2024-10-27 14:24:14
本文介绍了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问题

本文发布于:2023-10-08 08:47:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472114.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   Android   RecyclerView   Contextmenu

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!