简体   繁体   English

如何从上下文操作模式处理recyclerView项目的单击侦听器?

[英]How handle click listener for recyclerView item from contextual action mode?

在此处输入图片说明

I want to make recyclerview item click like this image.When i selected recyclerview item press long click then contextual action mode is enable.If i select only one item then show edit menu item else not.I want when i click edit menu item then click on recyclerView selected item and do some work.But i can't do it.Please help me some one.I am a new in android development. 我想让recyclerview项目像这张图片一样单击。当我选择recyclerview项目时,长按鼠标右键,然后启用上下文操作模式。如果我只选择一个项目,则不显示编辑菜单项目。当我单击编辑菜单项目然后单击在recyclerView上选择项目并做一些工作。但我做不到。请帮我一个。我是android开发中的新手。 Advanced Thank you. 高级谢谢。

I grab some info for you, that might be help for you, 我为您获取了一些信息,可能会对您有所帮助,

Once setSelectable() is implemented, you can achieve the rest of CHOICE_MODE_MULTIPLE_MODAL by using a regular ActionMode.Callback . 一旦实现setSelectable(),就可以使用常规的ActionMode.Callback来实现CHOICE_MODE_MULTIPLE_MODAL的其余部分。 Call through to your setSelectable() from within the relevant callback methods: 从相关的回调方法中调用您的setSelectable():

private ActionMode.Callback mDeleteMode = new ActionMode.Callback() {
        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            setSelectable(true);
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {
            setSelectable(false);
        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { ... }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { ... }
    }

Then use a long click listener to turn on the action mode: 然后使用长按侦听器打开操作模式:

private class CrimeHolder extends SwappingHolder
            implements View.OnClickListener, View.OnLongClickListener {

        ...

        public CrimeHolder(View itemView) {
            ...

            itemView.setOnClickListener(this);
            itemView.setOnLongClickListener(this);
            itemView.setLongClickable(true);
        }

        @Override
        public boolean onLongClick(View v) {
            ActionBarActivity activity = (ActionBarActivity)getActivity();
            activity.startSupportActionMode(mDeleteMode );
            setSelected(this, true);
            return true;
        }
    }

Let me know if you have any idea from this snippet. 让我知道您是否对此片段有任何想法。 if you want more go this link , which is great article by Bill Phillips . 如果您想要更多,请访问此链接 ,这是Bill Phillips的精彩文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有上下文操作模式的RecyclerView可以删除项目问题 - RecyclerView with Contextual Action Mode to delete an item issue Xamarin Android:在上下文操作模式下单击后退按钮时,如何取消选择recyclerview行 - Xamarin Android: How to unselect recyclerview rows when i click on the back button on contextual action mode 从上下文操作模式删除后,RecyclerView 复制项目 - RecyclerView duplicating items after deletion from contextual action mode 在Recyclerview片段中实现上下文操作模式的问题 - Problems with implementing contextual action mode in recyclerview fragment 如何处理项目单击侦听器上的RecyclerView及其行内的视图 - how to handle both RecyclerView on item click listener for its rows and the views inside it 如何使用Espresso框架单击上下文操作栏项 - How to click contextual action bar item using Espresso framework 当我单击上下文操作栏上的项目时如何插入菜单 - How to insert a menu when i click in a item on the contextual action bar Handle Button单击RecyclerView中的Listener - Handle Button click Listener in RecyclerView 如何处理Recyclerview列表项单击事件 - How to handle Recyclerview list item click event Recyclerview单个项目单击监听器 - Recyclerview individual item click listener
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM