Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
The custom adapter for emails list
public class EmailAdapter extends RecyclerView.Adapter<EmailViewHolder> {
private List<Email> emails;
private Context context;
public EmailAdapter(Context context, List<Email> emails) {
this.emails = emails;
this.context = context;
// creates the items and add them to the RecyclerView, just the layout
public EmailViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.email_item, parent, false);
return new EmailViewHolder(itemView);
// binds (displays) the content from the list of emails for each item
public void onBindViewHolder(@NonNull EmailViewHolder holder, int position) {
Email currentEmail = emails.get(position);
// we tell to the Recycler View how many items to display
public int getItemCount() {
return emails.size();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment