Android SectionedRecyclServiceAdapter实现getItemId

Android SectionedRecyclServiceAdapter实现getItemId,android,android-recyclerview,sectionedrecyclerviewadapter,Android,Android Recyclerview,Sectionedrecyclerviewadapter,我使用SectionedRecycleServiceAdapter作为我的RecycleView的适配器 使用RecycleServiceAdapter,如果我想唯一标识每一行,我将重写此方法: @Override public long getItemId( int position ) { return this.dataList.get(position).getId(); } 但如何使用SectionedRecyclServiceAdapter实现这一点?我的小节代码如下,我添

我使用SectionedRecycleServiceAdapter作为我的RecycleView的适配器

使用RecycleServiceAdapter,如果我想唯一标识每一行,我将重写此方法:

@Override
public long getItemId( int position ) {
    return this.dataList.get(position).getId();
}
但如何使用SectionedRecyclServiceAdapter实现这一点?我的小节代码如下,我添加了getId方法:

public class Section1 extends Section {
      .....

      public long getItemId(int position) {
        if (position == 0) {
          return 0;
        }

        return this.openPosList.get(position - 1).getId();
      }
}
我想我应该扩展SectionedRecyclServiceAdapter并覆盖getItemId。但我在这里无法将位置转换为节的行位置

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
           //  ????
     }

}

以前有没有人实现过类似的代码,有没有示例代码?谢谢

我在我的职位上找到并实现了这一点

在第1节课中:


发布了我自己的答案&希望下次有人发现它有用,谢谢

你想调用节的getID方法吗?@aborocz是的,最终我将调用节的getID
public class PositionRecyclerViewAdapter extends SectionedRecyclerViewAdapter {

    public PositionRecyclerViewAdapter() {
        super();
        ......

        this.setHasStableIds(true);
    }

    .......

    @Override
    public long getItemId (int index) {
        int viewType = this.getSectionItemViewType(index);
        Section1 section1 = (Section1) this.getSection(POSITION_SECTION);

        if (viewType == SectionedRecyclerViewAdapter.VIEW_TYPE_HEADER) {
            return section1.getHeaderId();
        } else if (viewType == SectionedRecyclerViewAdapter.VIEW_TYPE_ITEM_LOADED) {
            int sectionItemIndex = this.getPositionInSection(index);
            return section1.getItemId(sectionItemIndex);
        }

        return -1;
    }

}
public class Section1 extends Section {
    .....

    public long getHeaderId() {
        return headerId;
    }

    public long getItemId(int index) {
        return this.openPosList.get(index).getId();
    }
}