Skip to content

Instantly share code, notes, and snippets.

@amitshekhariitbhu
Created June 21, 2018 18:32
Show Gist options
  • Save amitshekhariitbhu/5aa62e9bfdf4b5fc4d16692e45149c65 to your computer and use it in GitHub Desktop.
Save amitshekhariitbhu/5aa62e9bfdf4b5fc4d16692e45149c65 to your computer and use it in GitHub Desktop.
public class PaginationAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
List<String> items = new ArrayList<>();
public PaginationAdapter() {
}
void addItems(List<String> items) {
this.items.addAll(items);
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return ItemViewHolder.create(parent);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
((ItemViewHolder) holder).bind(items.get(position));
}
@Override
public int getItemCount() {
return items.size();
}
private static class ItemViewHolder extends RecyclerView.ViewHolder {
ItemViewHolder(View itemView) {
super(itemView);
}
static ItemViewHolder create(ViewGroup parent) {
return new ItemViewHolder(
LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pagination, parent, false));
}
void bind(String content) {
((TextView) itemView).setText(content);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment