I am using SectionedRecyclerViewAdapter
from luizgrp/SectionedRecyclerViewAdapter as adapter for my RecyclerView.
With RecyclerViewAdapter, if I want to uniquely identify each row, I will override this method:
@Override
public long getItemId( int position ) {
return this.dataList.get(position).getId();
}
But how do I do that with SectionedRecyclerViewAdapter
? I have Section code as below, I added getId() method:
public class Section1 extends Section {
.....
public long getItemId(int position) {
if (position == 0) {
return 0;
}
return this.openPosList.get(position - 1).getId();
}
}
I think I shall extends SectionedRecyclerViewAdapter
& override getItemId()
. But I have problem converting the position
into Section's row position here.
public class PositionRecylerViewAdapter extends SectionedRecyclerViewAdapter {
......
@Override
public long getItemId(int position) {
// ????
// transform position here into Section's item position, considering multiple Sections with Header & Footer
// ????
}
}
Anyone implement similar code before, with any sample code? Thanks!
I figure it out & implement this in my
PositionRecylerViewAdapter
.In
Section1
class:Posted my own answer & hopefully someone finds it useful next time, thanks!