[x] Question. This issue tracker is not the place for questions. If you want to ask how to do
something, or to understand why something isn't working the way you expect it to, use Stack
Overflow. https://stackoverflow.com/questions/tagged/MultiType
public class MultiSelectActivity extends MenuBaseActivity {
private static final int SPAN_COUNT = 5;
Items items = new Items();
MultiTypeAdapter adapter;
Button fab;
private TreeSet<Integer> selectedSet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_multi_select);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
final GridLayoutManager layoutManager = new GridLayoutManager(this, SPAN_COUNT);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return (items.get(position) instanceof Category) ? SPAN_COUNT : 1;
}
});
selectedSet = new TreeSet<>();
recyclerView.setLayoutManager(layoutManager);
adapter = new MultiTypeAdapter();
adapter.register(Head.class, new HeadViewBinder(this));
adapter.register(Category.class, new CategoryItemViewBinder());
adapter.register(Square.class, new SquareViewBinder(selectedSet));
loadData();
assertAllRegistered(adapter, items);
recyclerView.setAdapter(adapter);
setupFAB();
}
private void loadData() {
Head head = new Head();
List<String> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
list.add("test" + i);
}
head.setTitle(list);
items.add(head);
Category spacialCategory = new Category("特别篇");
items.add(spacialCategory);
for (int i = 0; i < 7; i++) {
items.add(new Square(i + 1));
}
Category currentCategory = new Category("本篇");
items.add(currentCategory);
for (int i = 0; i < 100; i++) {
items.add(new Square(i + 1));
}
adapter.setItems(items);
adapter.notifyDataSetChanged();
}
private void setupFAB() {
fab = (Button) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
StringBuilder content = new StringBuilder();
for (Integer number : selectedSet) {
content.append(number + ' ');
}
Toast.makeText(v.getContext(),
"Selected items: " + content, Toast.LENGTH_SHORT)
.show();
}
});
}
}
Head 类
public class Head {
private List<String> title;
public List<String> getTitle() {
return title;
}
public void setTitle(List<String> title) {
this.title = title;
}
What kind of issue is this?
Info:
Description:
我们这里是这样的一个布局
我想的整体是一个RecyclerView 上面那块是Header (包含Banner+RecyclerView) 添加Header的方式是Items添加的第一个是Header这种方式 结果上面右侧RecyclerView显示有点问题,我用demo的例子试了试,也是一样的 以下代码我是在demo的MultiSelectActivity基础上测试的(Header只有一个RecyclerView)
代码
MultiSelectActivity类
Head 类
HeadViewBinder类
HeadAdapter类
item_head.xml类
item_head_layout.xml类