I have a layout with order list and last row is the total price of those order. And I don't have an idea that how can I do those list items and last row with my desire custom item, together in a recycler view. Do I make some logic in onBindViewHolder? Or, does it have another way, one of the RecyclerView methods?
You can do this by using below code on your RecyclerAdapter class
@Override
public int getItemViewType(int position) {
if(position==(getItemCount()-1))return 1;
else return 2;
}
In onCreateViewHolder inflate your last layout according to your viewType.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 1) {
// inflate your first item layout & return that viewHolder
} else {
// inflate your second item layout & return that viewHolder
}
}
Yes, you can do that using ItemTypes
,RecyclerView
can render different type of child views, Please refer to this example : RecyclerView With Multiple Item Types
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With