Skip to content

Instantly share code, notes, and snippets.

@zoltish
zoltish / Click.java
Created Apr 23, 2015
A simple helper class that wraps a View with a Click- and/or LongClick- Listener and stores it inside a tag. Wonderful for use everywhere, especially in RecyclerView.
View Click.java
public final class Click<T> implements View.OnClickListener, View.OnLongClickListener {
private final WeakReference<ClickCallback<T>> mClickWeakReference;
private final WeakReference<LongClickCallback<T>> mLongClickWeakReference;
T mItem;
private Click(ClickCallback<T> callback, LongClickCallback<T> longClickCallback) {
mClickWeakReference = callback != null ? new WeakReference<>(callback) : null;
mLongClickWeakReference = longClickCallback != null ? new WeakReference<>(longClickCallback) : null;
You can’t perform that action at this time.