MultichoiceModeListener on RecyclerView android

2019-02-27 15:36发布

I have a recyclerview with respective adapter. I want to show multiple customview menu options in toolbar on the long press of recyclerview item. Any help is highly appreciated. Thanks in advance.

1条回答
倾城 Initia
2楼-- · 2019-02-27 16:03

I'm doing the same work. This post is helpful: RecyclerView with choice modes

Basically you have to add this code in your OnLongClick method

 @Override
public boolean onLongClick(View view) {
    if (!mMultiSelector.isSelectable()) {
        ((AppCompatActivity) getActivity()).startSupportActionMode(mActionModeCallback); // (2)
        mMultiSelector.setSelectable(true);
        mMultiSelector.setSelected(MyViewHolder.this, true);
        return true;
    }
    return false;
}

Hope it helps

查看更多
登录 后发表回答