ribot / easy-adapter

[DEPRECATED] Easy Adapters library for Android
http://ribot.github.io
Apache License 2.0
421 stars 50 forks source link

Feature listener support #23

Closed ivacf closed 9 years ago

ivacf commented 9 years ago

This pull requests adds a new parameter to the easy adapter constructors so now it's possible to pass a generic Object to the ItemViewHolder through the Adapter. This allows to pass a listener into the ItemViewHolder that then can be get and called when an action happens, i.e click on a view.

The ItemViewHolder also providers a method getListener(Class type) that casts the listener Object to the desired type and retruns it.

This new argument is optional so it won't cause any breaking changes.

jsonfry commented 9 years ago

For the record, Ivan and I just had a conversation about the naming of this new feature. I expressed a concern about calling this a listener, when it is a generic Object, that could in theory be used for anything.

I suggested calling it a 'tag' instead, using a similar pattern to an android View. Ivan said he had thought about this, and decided that using it like that opens it up to abuse and bad code, as all the data should be within the data list. We then looked at the documentation for setTag:

http://developer.android.com/reference/android/view/View.html#setTag(java.lang.Object) Sets the tag associated with this view. A tag can be used to mark a view in its hierarchy and does not have to be unique within the hierarchy. Tags can also be used to store data within a view without resorting to another data structure.

As this explicitly mentions using it for data, we decided not to use 'tag' but instead keep it as a listener, as that's what it's intended for, and if people want to misuse it, it's clearer that they're doing this.

jsonfry commented 9 years ago

Are you gonna update the README for this?

ivacf commented 9 years ago

Yes

jsonfry commented 9 years ago

In this pull request, or once it's in maven central?

ivacf commented 9 years ago

Once it's in maven central

jsonfry commented 9 years ago

Great!