0

enter image description here

after releasing the long click, the item is getting deselected automatically.

holder.attach_img.setOnLongClickListener(new View.OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    if (lvChatList.isItemChecked(position))
                        lvChatList.setItemChecked(position, false);
                    else
                        lvChatList.setItemChecked(position, true);
                    notifyDataSetChanged();
                    return false;
                }
            });
Rathan Kumar
  • 2,567
  • 2
  • 17
  • 24

1 Answers1

0

As you may know, the View hierarchy in Android is represented by a tree. When you return true from the onLongClick() - it means that the View that currently received the event is the true event receiver and the event should not be propagated to the other Views in the tree; when you return false - you let the event be passed to the other Views that may consume it. So for your current scenario, just make onLongClick(View view) returns return true instead of return false and check this https://developer.android.com/reference/android/view/View.OnLongClickListener.html

@Override
    public boolean onLongClick(View view) {
        if (lvChatList.isItemChecked(position))
                    lvChatList.setItemChecked(position, false);
                else
                    lvChatList.setItemChecked(position, true);
                notifyDataSetChanged();
                return true;
    }
yashkal
  • 713
  • 5
  • 20
  • yes after returning true also, same like after releasing the long click its happening – Rathan Kumar Nov 07 '17 at 15:13
  • will you able to show your some more code, because i have implemented it on my sample app, if you want to i can show you my code. – yashkal Nov 08 '17 at 11:50