Skip to content

Instantly share code, notes, and snippets.

Last active September 12, 2018 09:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
What does Adapter do? Understanding RecyclerView

Adapter class is a helper to RecyclerView. It has three responsibilities: To return how many items should be in RecyclerView, inflate item views from XML and return new ViewHolder instance(object). and populate them with appropriate data(Basically, everything is in this order). So, it has (constructor and) three methods:


public MyAdapter(int numberOfItems, ListItemClickListener onClickListener)

where ListItemClickListener is an interface, which has one void methoid defined, onListItemClick.

ViewHolder OnCreateViewHolder(params)

This method inflates item XML and wraps it into ViewHolder.

void onBindViewHolder(params)

This method binds/populates view with data. I also have to mention that ViewHolder class must contain void bind(params), which is then called inside onBindViewHolder.

int getItemCount()

This method returns number of items from data source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment