我正在使用来自SectionedRecyclerViewAdapter的luizgrp/SectionedRecyclerViewAdapter作为RecyclerView的适配器。
我们可以使用Section
布局将SectionedRecyclerViewAdapter
添加到Header
中,如下所示:
public class Section1 extends Section {
public Section1 () {
super(
R.layout.section_1_header,
R.layout.section_1_item,
R.layout.section_1_loading,
R.layout.section_1_failed
);
}
.....
}
.....
Section1 section1 = new Section1();
section1.setState(Section.State.LOADING);
SectionedRecyclerViewAdapter sectionAdapter = new SectionedRecyclerViewAdapter();
sectionAdapter.addSection(section1);
recyclerView.setAdapter(sectionAdapter);
在loading
状态期间,我将显示一个在section_1_loading.xml
中定义的旋转进度条。但我的问题是,当部分仍然在header
中时,loading state
已经显示出来了。如何在状态更改为loaded
之前隐藏标头
我考虑的只是在状态更改到header
之后将loaded
添加到节中。但似乎无法作为唯一的方式设置区段的标题是在区段的构造函数中。
有人知道吗?谢谢!
发布于 2017-05-19 00:15:21
尝试重写SectionedRecyclerViewAdapter类并在onBindViewHolder
中替换
if (section.hasHeader())
通过
if (section.hasHeader() && section.getState() != Section.State.LOADING)
发布于 2017-05-19 20:10:33
我现在设法使它发挥作用,上面是亚历山大的暗示。解决办法是:
// loading state - set no header so header section is hidden
section1.setHasHeader(false);
section1.setState(Section.State.LOADING);
....
....
// loaded state - set has header so header section is shown
section1.setHasHeader(true);
section1.setState(Section.State.LOADED);
谢谢!
https://stackoverflow.com/questions/44063923
复制