1

If you know in Telegram to delete chat or group we hold item(long press) and clicking another item then we add the group to chat, to delete the list, I cant do it.

Currently I can listening just only click like this:

 itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(itemView.getContext(),"Short Click",Toast.LENGTH_SHORT).show();
        }
    });

and listening long click:

 itemView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(itemView.getContext(),"Short Click",Toast.LENGTH_SHORT).show();
            return false;
        }
    });

In my case, I want to listen to long-press and then I want to highlight item(of course, the item is part of recyclerView) with just click(not long click) I googled but it did not help me.

Muhammad Farhan
  • 1,113
  • 10
  • 22
Rustam
  • 71
  • 1
  • 6
  • Does this answer your question? [How to implement multi-select in RecyclerView?](https://stackoverflow.com/questions/36369913/how-to-implement-multi-select-in-recyclerview) – Bek Feb 14 '20 at 04:49
  • in this case There are using item click (short click), I can do it, in my case I have to use first long click and then highlight another item with click(not long) – Rustam Feb 14 '20 at 04:55
  • 1
    In your OnLongClickListener you can iterate through recyclerView items ant set new OnClickListener to select them. Also, you need to store some flag to switch behaviour in onBindViewHolder. – Bracadabra Feb 14 '20 at 07:38
  • @Bracadabra thanks a lot ! I solved this question like in your case... – Rustam Feb 14 '20 at 11:17
  • Cool, glad to help, then I will move the comment to answers not to leave the question open. – Bracadabra Feb 14 '20 at 11:23

1 Answers1

1

I believe the simplest solution is the following:

  1. In OnLongClickListener iterate through RecyclerView views and set new OnClickListener to handle selection.
  2. Store some flag to switch behavior in onBindViewHolder.
Bracadabra
  • 3,609
  • 3
  • 26
  • 46