Search code examples
androidandroid-layoutviewandroid-recyclerviewandroid-view

setOnClickListener for recyclerView not working


For RecyclerView if it has not any item, then click on RecyclerView works, but if it has items clicking on RecyclerView doesn't work. Be careful I mean click on just RecyclerView not RecyclerView's item

recyclerView.setOnClickListener(view -> {Timber.d("recyclerView clicked");});

How I can set RecyclerView clickable even it has items on it.


Solution

  • but if it has items clicking on RecyclerView doesn't work

    Why do you think that you are performing a click on the RecyclerView itself? Most possibly the item of the RecyclerView swallows the touch event, thus it won't be reached to the RecyclerView. You can make the children of RecyclerView to be not clickable, then the next item that would be given a chance to respond to click event would be the RecyclerView.