1

I use this code to give header items in a RecyclerView a span of two columns using a GridLayoutManager:

MyAdapter myAdapter = new MyAdapter(this, items);
this.myRecyclerView.setAdapter(myAdapter);

GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        switch (myAdapter.getItemViewType(position)) {
            case -1: // VIEW_TYPE_ITEM
                return 1;
            default: // VIEW_TYPE_HEADER
                return 2;
        }
    }
});
this.myRecyclerView.setLayoutManager(layoutManager);

This works, but it complains about my usage of getItemViewType, because it's deprecated. My adapter extends SectionedRecyclerViewAdapter<RecyclerView.ViewHolder>.

What should I use, instead?

(Also, I don't know about the enum that I should use in the switch statement, instead, but this is a different story.)

Martin Braun
  • 10,906
  • 9
  • 64
  • 105
  • which version of recycler-view are you used? and in which version `getItemViewType` is deprecated? – beigirad Mar 31 '21 at 10:26
  • @beigirad that's for asking. This entire question is a mistake, though. I'm editing a project that uses a `SectionedRecyclerViewAdapter` and I failed to recognize that it's not part of the Android library, so this question cannot be answered. – Martin Braun Apr 02 '21 at 20:20

1 Answers1

1

you have to use recyclerview viewpool great way to do section recyclerview like google play its inbuilt functionality of recyclerview.

eg of section recyclerview -

https://www.youtube.com/watch?v=EyUjw6b5gXE

https://github.com/alghifari/RecycledViewPoolExample

axar
  • 539
  • 2
  • 17