Created
June 21, 2018 18:32
-
-
Save amitshekhariitbhu/5aa62e9bfdf4b5fc4d16692e45149c65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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