This question has already been answered:

As you know, in a running CardView application, overwhelmingly generated and displayed programmatically. Is it possible to insert anything in front of a certain card?

Example: adding a textview in a gallery type application in front of a card with a photo and the name of the photo:

enter image description here

Reported as a duplicate by pavlofff android Dec 1 '16 at 7:24

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Also see this answer with a more detailed description of how to make the headers yourself. You may be more comfortable using one of the ready-made libraries . - pavlofff

1 answer 1

Can. You can override the getItemViewType(int position) method in RecyclerView . Accordingly, when you create a ViewHolder in the ViewHolder method onCreateViewHolder you will know the type, and you can accordingly create another item

  • Thank you for your reply! Unfortunately, I didn’t quite understand you: how exactly to redefine getItemViewType(int position) and how it will let know types - Lateral Gleb
  • You can determine for some same data that you need to add a TextView in this item. You can recognize this data in getItemViewType(int position) retrieving it by position. Here is an example of stackoverflow.com/a/26245463/7104538 - pavel163