Android: RecyclerView item Contextmenu issue

柔情痞子 提交于 2019-12-23 19:12:19

问题


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.

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: Attempt to read from field 'long com.x.lib.RVCoursesContextMenu$RecyclerContextMenuInfo.id' on a null object reference

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.


回答1:


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

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


来源:https://stackoverflow.com/questions/33369209/android-recyclerview-item-contextmenu-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!