Items groups separator list
pinicius opened this issue · 2 comments
Hi Pedro,
I have a list items sorted and grouped by type. Is possible render this list with separators between groups of items?
I've done many tests but I've not achieved :_(
I tried to return in the method inflate() two different views depending on some PanelItemViewModel parameter but when I call getContent() method always return null.
CurrentDistributionPanelItemViewModel
public class CurrentDistributionPanelItemViewModel {
private final WorkOrderLineViewModel workOrderLine;
private final CurrentDistributionPanelSeparatorViewModel separator;
public CurrentDistributionPanelItemViewModel(WorkOrderLineViewModel workOrderLine,
CurrentDistributionPanelSeparatorViewModel separator) {
this.workOrderLine = workOrderLine;
this.separator = separator;
}
public boolean isSeparator() {
if(separator != null) {
return true;
}
return false;
}
public WorkOrderLineViewModel getWorkOrderLine() {
return workOrderLine;
}
public CurrentDistributionPanelSeparatorViewModel getSeparator() {
return separator;
}
}
CurrentDistributionPanelItemRenderer.java
...
@Override
protected View inflate(LayoutInflater inflater, ViewGroup parent) {
View v = null;
if(getContent().getWorkOrderLine() == null) {
}
else {
v = inflater.inflate(R.layout.work_order_line, parent, false);
resource = (TextView) v.findViewById(R.id.resource);
costGroup = (TextView) v.findViewById(R.id.cost_group);
unitsLabel = (TextView) v.findViewById(R.id.units_label);
unitsValue = (TextView) v.findViewById(R.id.units_value);
}
return v;
}
How can I achieve it?
Thanks
Using the same renderer to implement your list with separators is going to be a problem. If you review the recycler view / list view implementation if you use the same view holder/renderer to represent your row you'll have to recycle it and keep in mind that some items will have to be hidden or not depending on the view model type.
My recommendation is to create an interface and two different implementations, one for your separator and another one for your item. Then create two different renderers associated with your separator class to the separator renderer. Before to reload your recycler view configure the adapter used with items as you need. If you need a list with 2 items and 2 separators you can fill your list as follows:
- Item to show.
- Separator.
- Item to show.
- Separator.
Is this the answer to your question?
Of course Pedro, Thanks.
I'll probe your recommendation.
For now, I've implemented it with default adapters.