taltstidl / Swipeable-RecyclerView

A library that provides an easy and customizable way to implement a swipe to dismiss pattern with RecyclerView.
Apache License 2.0
87 stars 17 forks source link

Add `onItemClick()` callback #9

Closed DenisMondon closed 8 years ago

DenisMondon commented 8 years ago

Hi,

Nice library! I was wondering how to implement an OnItemClickListener for each item. Do you have any ideas?

Thanks. Denis

taltstidl commented 8 years ago

@DenisMondon Handling click events is not covered by this library as its primary aim was to add simple support for swiping list items. You should refer to other resources on the web for this instead (such as http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/). Seeing how difficult this has become though, I might consider adding a callback for this similiar to the onSwipe() callback in the future.

DenisMondon commented 8 years ago

@TR4Android Thanks for the answer :) I will read this article :) And I think it could be a good feature like onSwipe()!! ;)

Thanks!

taltstidl commented 8 years ago

@DenisMondon Sure :smiley: Like I said, I will look into adding this in the future, for now you'll have to implement click handling yourself though.

DenisMondon commented 8 years ago

The article works with my "normal" Adapter (without swipe), but not with yours (SwipeAdapter). For me, the only code that changes is:

return new ViewHolder(layoutInflater.inflate(R.layout.my_layout, parent, false);

Your code uses true (for the attachToRoot parameter).

Do you have any ideas?

taltstidl commented 8 years ago

@DenisMondon I'll look into this and add support for item clicks as soon as I can! Bear with me.

taltstidl commented 8 years ago

@DenisMondon What excactly does not work? Is the click never registered or is there an exception?

DenisMondon commented 8 years ago

The click is never registered...

taltstidl commented 8 years ago

@DenisMondon You could try setting your click listener to a specific View (using an id). Does that work?

taltstidl commented 8 years ago

@DenisMondon I decided against this as it's pretty simple to implement actually. I did however update the sample code to reflect this and added click listener to the items there (see commit 0ad6e5d147e608e29db14d0b9ddfb42a28fbe9ee and the updated SampleAdapter and item_sample) I'm closing this in favor of developers own implementations. If you have any trouble getting the sample code to work for you, you can still ask for help here.