gpt4 book ai didi

android - 滚动 Android StickyHeaderGrid

转载 作者:行者123 更新时间:2023-11-30 04:54:51 31 4
gpt4 key购买 nike

我正在使用 RecyclerViewStickyHeaderGridAdapter
我正在尝试滚动到特定位置,但是当我打电话时我的recyclerview.scrollTo(我的位置)它不能正常工作,它会滚动到一些以前的项目。
我搜索了 allot 但不幸的是我没有找到任何解决方案。

这是我的适配器:

public class PartsAdapter extends StickyHeaderGridAdapter {

public List<SessionHeaderJavaModel> headers;
private LinkedHashMap<SessionHeaderJavaModel , List<PartJavaModel>> mainList;

public PartsAdapter() {
this.mainList = new LinkedHashMap<>();
}

@Override
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int headerType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
PartHeaderItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.part_header_item, parent, false);
return new MyHeaderViewHolder(binding);
}

@Override
public ItemViewHolder onCreateItemViewHolder(ViewGroup parent, int itemType)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
PartItemBinding binding = DataBindingUtil.inflate(inflater, R.layout.part_item, parent, false);
return new MyItemViewHolder(binding);
}

@Override
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int section)
{
((MyHeaderViewHolder)viewHolder).setHeaderModel(this.headers.get(section));
}

@Override
public void onBindItemViewHolder(ItemViewHolder viewHolder, int section, int offset) {
mainList.get(this.headers.get(section)).get(offset).setSection(offset);
((MyItemViewHolder)viewHolder).setItemModel(mainList.get(this.headers.get(section)).get(offset));
}

@Override
public int getSectionCount() {
if(mainList!=null)
return mainList.size();
return 0;
}

@Override
public int getSectionItemCount(int section) {
if(mainList!=null && headers!=null && mainList.get(this.headers.get(section))!=null)
return mainList.get(this.headers.get(section)).size();
return 0;
}

然后我像这样初始化我的recylcerview:

PartsAdapter adapter=new adapter();
StickyHeaderGridLayoutManager mLayoutManager = new StickyHeaderGridLayoutManager(1);

recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(adapter);

最佳答案

答案是:

 recyclerView.scrollToPosition(newPosition + items.get(newPosition).getSessionNo());

我们应该考虑 headerItem 。

关于android - 滚动 Android StickyHeaderGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59437211/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com