2

In onCreateViewHolder(ViewGroup parent, int viewType) I do not understand the purpose of the parent and viewType parameters.

Can anyone explain with an example?

In my RecyclerView, I am using an ImageView and a TextView to display an item of the RecyclerView.

skomisa
  • 16,436
  • 7
  • 61
  • 102
sh ra
  • 41
  • 2

1 Answers1

1

Parent : The ViewGroup is the parent view that will hold your cell that you are about to create. So, the ViewGroup parent is the RecyclerView here (it will hold your cell). The parent is used during the layout inflation process so you can see it passed in to the inflate call.

ViewType : The viewType is useful if you have different types of cells in your list. For example, if you have a header cell and a detail cell. You can use the viewType to make sure that you inflate the correct layout file for each of those two types of cells.

Masum
  • 1,037
  • 15
  • 32