多个 RecyclerViews 和适配器数据偏移

Multiple RecyclerViews and adapter data offset

我有多个使用通用 RecyclerView.Adapter 的 RecyclerView。有什么方法可以告诉 RecyclerView 使用一些偏移量从适配器获取数据吗?诸如第一个视图从适配器获取 0-15 个项目,第二个视图获取 15-30 个等等。

你的意思是 ExpandableListView?

已编辑: 试试这个。 在所需位置为过滤后的数据创建单独的数据结构

private List<Object> data;
private List<Object> dataToShow;
public CustomAdapter(List<Object> data){
     this.data = data;
     this.dataToShow = new ArrayList<>(data);
}

...在所有覆盖方法中使用 dataToShow 字段

创建过滤数据的方法

public void showDataAtPositions(int startPos, int endPos){
    dataToShow.clear();
    for(int index = 0; index < data.size(); index++){
        if(index >=startPos && index <= endPos){
            dataToShow.add(data.get(index));
        }
    }
    notifyDataSetChanged();
}

然后就调用这个方法

adapter.showDataAtPositions(0, 15);
adapter.showDataAtPositions(16, 30);

这应该有效

在 FragmentStatePagerAdapter 将位置和对象列表提供给 viewpager 中的片段:

 @Override
        public Fragment getItem(int position) {
            return YourFragment.newInstance(position,yourListOfObjects);
        }

然后在 YourFragment 中根据位置从列表中取出 15 项并制作一个适配器,例如使用 RxJava,但您可以修改它,以使用常规 Java:

int positionOfFragment;
        List<Product> list;
        Observable
                .just(list)
                .take(positionOfFragment*15)
                .subscribe(new Action1<List<Product>>() {
                    @Override
                    public void call(List<Product> orders) {
                        ProductAdapter adapter = new ProductAdapter(orders, getActivity());
                        //setAdapter to RecyclerView;
                    }
                });