如何创建RecyclerView上下文菜单

如何创建RecyclerView上下文菜单

本文介绍了如何创建RecyclerView上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何落实 RecyclerView?上下文菜单显然调用 registerForContextMenu(recyclerView)不起作用。我是从一个片段调用它。没有任何人有任何的成功实施呢?

解决方案

 公共静态类ViewHolder扩展RecyclerView.ViewHolder实现OnCreateContextMenuListener {
TextView的tvTitle;
ImageView的ivImage;
    公共ViewHolder(视图v){
        超级(五);
        tvTitle =(TextView中)v.findViewById(R.id.item_title);
        v.setOnCreateContextMenuListener(本);


    }
 

现在我们按照相同的步骤,同时实现了上下文菜单。

  @覆盖
    公共无效onCreateContextMenu(文本菜单菜单,视图V,
            ContextMenuInfo menuInfo){

        menu.setHeaderTitle(选择操作);
        menu.add(0,v.getId(),0,呼叫); //的groupId,的itemId,秩序,标题
        menu.add(0,v.getId(),0,SMS);

    }
 

如果你得到任何困难,请在评论。骄傲是一个androidian:)

How do I implement context menu for RecyclerView? Apparently calling registerForContextMenu(recyclerView) doesn't work. I'm calling it from a fragment. Did anybody have any success implementing this?

解决方案
public static class ViewHolder extends RecyclerView.ViewHolder implements OnCreateContextMenuListener {
TextView tvTitle;
ImageView ivImage;
    public ViewHolder(View v) {
        super(v);
        tvTitle =(TextView)v.findViewById(R.id.item_title);
        v.setOnCreateContextMenuListener(this);


    }

Now we follow the same procedure while implements the context menu.

@Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {

        menu.setHeaderTitle("Select The Action");
        menu.add(0, v.getId(), 0, "Call");//groupId, itemId, order, title
        menu.add(0, v.getId(), 0, "SMS");

    }

if you get any difficulties ask in comment. Proud to be an androidian :)

这篇关于如何创建RecyclerView上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 04:16