Android RecyclerView with header, footer and pagination

RecyclerView

Anu S Pillai

The Admin at GadgetSaint.com

You may also like...

17 Responses

  1. Anonymous says:

    Very nice blog.briefly discussed all the required topics.

  2. Jumperz says:

    Quick question.

    Does these headers and footers take position? And if they do, how can I “remove their position”?

    Id like to use this mainly for just the header. And then pass data to the itemView from an ArrayList using a SQL database. I need the position in itemView click to match the _id in sqlite so I can update them.

  3. Anu S Pillai says:

    Hi Jumperz, these header and footer will take positions. As in your case the zeroth position will be held by the header. Have you tried handling it by something like newPositition = position – 1; and then use the newPositition as your variable to match with sqlite.

  4. Jumperz says:

    Hey Anu,

    Yes, I have tried that. And it works great for just the first item. The layout I have is going to be dynamic. If you take a look at the image below, I placed positions highlighted in red to their corresponding placement.

    https://i.imgur.com/zYWkIcW.png

    Any idea how I can get around this?

  5. Anu S Pillai says:

    Okay so number highlighted in red are the items right? Which one is the header?

  6. Jumperz says:

    That is all the positions from the page.

    The headers are positions 0, 2 & 6.

    Subtracting the position works well for the first iteration. After that it stops and counts normal. I ran a simple IF ELSE statement to check by “type” and for some reason, it still doesn’t account for the rest of the headers. It only accounts for the first one.

  7. Anu S Pillai says:

    Do you know in advance that position 0,2,6…etc will be of type “Header”?

  8. Jumperz says:

    Nope. They’re all dynamic. But I figured it out.

    Thank you though!

  9. Anu S Pillai says:

    Cool. Can you tell briefly how you did that?

  10. Jumperz says:

    Sure, I’m not a techy programmer like you are though, so bear with the lingos. 😛

    Basically, since recyclerview likes models, i just added another parameter to the class that will contain the row_id form sql. I just called it “String rowId…whatever”. Each time I populate the models with arraylists, I include the cursor to pass the ROW_ID table from SQL to it. So whenever I details when I click on the item(not the header), I explicitly tell the database to look for the row_id model field instead of looking for “position”.

  11. Sandep Pal says:

    i have a rest api in which there are 10 pages and in each page there are 10 videos , i want to do pagination so that when user scrolls then next 10 videos should be fetched from api and page no should change to 0 to 1 and again when user scrolls then page should change from 1 to 2 and so on and next 10 videos should be fetched . PLease help me to do same. I am using retrofit and in my base url i have put pageno as a counter , i am not able to understand where should i increment that counter. Please help me.

  12. Anu S Pillai says:

    You should increment the page number in addonscrolllistener as shown in the example fetchdata()

  13. Denis says:

    Thank you for your guid. It was very helpful for me.

  14. Anu S Pillai says:

    You are welcome 🙂

  15. Great work…Only station which helped me…

  16. Hello, thanks for this nice article and WELL write with all code we just to need of course to understand and copy paste all for all works …

    you save my time today 🙂 🙂
    i must to realize the same thing but with android xamarin

    Last word, thanks for sharing your knowledge that’s really nice guy …
    continue as that 🙂

    Christophe from belgium

  17. Anu S Pillai says:

    Sure man. Thanks 🙂

Leave a Reply

Your email address will not be published.