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?
Asked
Active
Viewed 1,590 times
7
-
1you can do this by getting last item position – Abhishek kumar Jan 29 '18 at 08:19
-
You can use Recycler view header and footer. – Chithra B Jan 29 '18 at 08:20
-
Thank you @Chithra , you saved my day. I almost do some logic in onBindViewHolder. – KyawLinnThant Jan 29 '18 at 08:27
-
Glad that it helped! – Chithra B Jan 29 '18 at 09:19
3 Answers
4
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
}
}

Abhishek kumar
- 4,347
- 8
- 29
- 44
3
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

Rajan Kali
- 12,627
- 3
- 25
- 37
0
You can use simple relative or linear layout to display Total price of those orders.
And this layout will place below the recyclerview / Listview in XMl.
if you use above solution then you don't need to use last item of list for displaying total price of those orders.

sandeep kolhal
- 393
- 1
- 4
- 14