I have a viewholder that has linear layout inside it.
The linear layout has an onClickListener that starts a new activity.
my entire ViewHolder, though, has a LongClickListener that operates a different logic.
When adding the click listener to the linearLayout inside the ViewHolder, only that click listener is working, and it disables the linear layout and the entire ViewHolder from being able to be "long clicked".
How can I make both of them live together peacefully and happy?
here is my click listener being added -
contactHolder.getSendContactLay().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<Contact> contacts = new ArrayList<>();
Contact c = new Contact();
c.setContactName(contactMessage.getName());
c.setContactNos(String.valueOf(contactMessage.getPhoneNumber()).replace("]","").replace("[",""));
contacts.add(c);
((Activity) context).startActivityForResult(new Intent(context,
PickContactActivity.class).putParcelableArrayListExtra(Constants.USERNAME,
(ArrayList<Contact>) contacts),
Constants.SELECT_CONTACT_REQ_CODE);
}
});
and here is my long click listener -
public void handleItemClick() {
ItemClickSupport.addTo(listChats).setOnItemLongClickListener((recyclerView, position, v)
-> {
onItemLongClick(position);
return true;
});
ItemClickSupport.addTo(listChats).setOnItemClickListener((recyclerView, position,
v) -> {
hideKeyboard();
if (!clickedMessages.isEmpty())
onItemClick(position);
});
}
when debugging and trying to long click the viewholder - it does not even trigger the long click method.
How can I make them live together?
make sure your parent view is clickable :
android:clickable="true"you could try implement
OnTouchListenerand returnnull