Skip to content

Instantly share code, notes, and snippets.

@wightwulf1944
Last active February 13, 2019 12:10
Show Gist options
  • Save wightwulf1944/0b2754e528d706d40b529fb7a47b2295 to your computer and use it in GitHub Desktop.
Save wightwulf1944/0b2754e528d706d40b529fb7a47b2295 to your computer and use it in GitHub Desktop.
adapter bind listener pattern
public class RelevantBindListener {
public RelevantBindListener() {
SampleAdapter adapter = new SampleAdapter();
adapter.setOnLastItemBindListener(this::onAdapterLastItemBind);
}
private void onAdapterLastItemBind() {
// THIS IS CALLED WHEN THE LAST ADAPTER ITEM IS BIND.. BOUND? BINDED??
}
}
public class SampleAdapter extends RecyclerView.Adapter {
private Runnable onLastItemBindListener;
public void setOnLastItemBindListener(Runnable onLastItemBindListener) {
this.onLastItemBindListener = onLastItemBindListener;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (position == getItemCount() - 1) {
onLastItemBindListener.run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment