KyawLinnThant
KyawLinnThant

Reputation: 617

Can recyclerView have the last row with custom item that does not same with the other items?

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?

Upvotes: 7

Views: 1675

Answers (3)

sandeep kolhal
sandeep kolhal

Reputation: 423

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.

Upvotes: 0

Abhishek kumar
Abhishek kumar

Reputation: 4445

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
    }
}

Upvotes: 4

Rajan Kali
Rajan Kali

Reputation: 12953

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

Upvotes: 3

Related Questions