Skip to content

Instantly share code, notes, and snippets.

Embed
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
@NonNull
@Override
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
@Override
public void onBindViewHolder(@NonNull EmailViewHolder holder, int position) {
Email currentEmail = emails.get(position);
holder.getTextViewFrom().setText(currentEmail.getFromName());
holder.getTextViewSubject().setText(currentEmail.getSubject());
holder.getTextViewBody().setText(currentEmail.getShortBody());
}
// we tell to the Recycler View how many items to display
@Override
public int getItemCount() {
return emails.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.