7

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?

Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
KyawLinnThant
  • 617
  • 1
  • 9
  • 20

3 Answers3

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