答案 0 :(得分:-3)
您可以使用ViewType的帮助。
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_ITEM) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.scheduler_settings_days_row, parent, false);
return new ViewHolderItems(v);
} else if (viewType == TYPE_HEADER) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.scheduler_settings_days_row_header, parent, false);
return new ViewHolderHeader(v);
} else if (viewType == TYPE_FOOTER) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.scheduler_settings_days_row_footer, parent, false);
return new ViewHolderFooter(v);
} else {
return null;
}
//throw new RuntimeException("there is no type that matches the type " + viewType + " + make sure your using types correctly");
}
@Override
public int getItemViewType(int position) {
if (isPositionHeader(position)) {
return TYPE_HEADER;
} else {
return TYPE_ITEM;
}
private boolean isPositionHeader(int position) {
return position == 0;
}