我正在尝试在单个recyclerview中实现两个不同的列表视图以及其他项目。
适配器的getItemViewType()是:
@Override
public int getItemViewType(int position) {
if(isPositionTitle(position))
return TYPE_TITLE;
if(isPositionTitleList(position))
return TYPE_TITLE_ITEM;
if(isPositionAdd(position))
return TYPE_TITLE_ADD;
if(isPositionSeperator(position))
return TYPE_SEPERATOR;
if(isPositionTicked(position))
return TYPE_TICKED;
if(isPositionTickedList(position))
return TYPE_TICKED_LIST;
return 0;
}
private boolean isPositionTitle(int position)
{
return position == 0;
}
private boolean isPositionTitleList(int position)
{
return position == 1;
}
private boolean isPositionAdd(int position)
{
return position == 2;
}
private boolean isPositionSeperator(int position)
{
return position == 3;
}
private boolean isPositionTicked(int position)
{
return position == 4;
}
private boolean isPositionTickedList(int position)
{
return position == 5;
}
@Override
public int getItemCount() {
return tickedList.size()+titleList.size()+4;
}
问题是两个列表中只显示第一个列表项。如何显示列表视图中的所有项目?
Recyclerview设置代码:
rv = (RecyclerView) findViewById(R.id.act1_recycler);
MyLinearLayoutManager llm = new MyLinearLayoutManager(this.getApplicationContext(),LinearLayoutManager.VERTICAL,false);
rv.setLayoutManager(llm);
adapter = new Activity8Adapter(getApplicationContext(),titleList,tickedList);
rv.setAdapter(adapter);