0

I’m trying to display different views in a RecyclerView using the FirestorePagingAdapter basing on a field value returned from the database (which is type). How can I modify this to set a specific view to the RecyclerView for each list item. Firestore Structure

  FirestorePagingAdapter<FeedItem, FeedViewHolder> pagingAdapter = new FirestorePagingAdapter<FeedItem, FeedViewHolder>(options) {

            @NonNull
            @Override
            public FeedViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                // HANDLE VIEW TYPE
                return null;
            }

            @Override
            protected void onBindViewHolder(@NonNull FeedViewHolder holder, int position, @NonNull FeedItem model) {
                // ADD DATA TO VIEW
            }
        };
Reypak_UG
  • 13
  • 1
  • If you understand Kotlin and you want to learn a modern way in which you can paginate Firestore documents, then this [resource](https://medium.com/firebase-tips-tricks/how-to-implement-pagination-in-firestore-using-jetpack-compose-76b4c0b5acd5) will help. Here is the corresponding [repo](https://github.com/alexmamo/FirestorePaginationJetpackCompose). – Alex Mamo Aug 08 '23 at 05:51

1 Answers1

0

You'll need to implement getItemViewType in addition to the methods you already have.

The flow is that:

  1. the adapter first calls your getItemViewType method with the position of the item it wants to render,
  2. you then return a number that indicates the type of view you want to render for the position,
  3. the adapter then calls onCreateViewHolder with the type,
  4. you use that to create and return a view of the correct type, which
  5. the adapter them passes to onBindViewHolder.

For examples of this, see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807