Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Class that allows to check number of clicks available on a view
public class RetryClickListener implements View.OnClickListener {
private int maxRetries;
private int current = 0;
private OnRetryClickListener onRetryClickListener;
public RetryClickListener(int maxRetries, OnRetryClickListener onRetryClickListener) {
this.maxRetries = maxRetries;
this.onRetryClickListener = onRetryClickListener;
}
@Override
public void onClick(View v) {
if (onRetryClickListener != null) {
if (current++ < maxRetries) {
onRetryClickListener.onClick(v);
} else {
onRetryClickListener.onClickNotAllowed(v);
}
}
}
public interface OnRetryClickListener {
void onClick(View v);
void onClickNotAllowed(View v);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment