Posted on

Awesome Android RecyclerView Library


simplest android recyclerview library

Designed by Freepik

Integrating RecyclerView isn’t hard. But there’s features that you need to implement yourself: pagination (load more, display ProgressBar as a footer), nothing found text and initial load ProgressBar. Those are really common, although easy to implement – you can end up ether copy/pasting from your previous projects or worse – rewriting from scratch, because it’s so easy to implement. Ether of those options aren’t great, let’s find a library that can do all that

Search For Library

Obviously there’s gonna be dozens of RecyclerView libraries out there on GitHub, because RecyclerView api itself is so easy to use, plus those libraries are just going to be built on top of that api. What I want for now is pagination (load more with ProgressBar) and show nothing found text.

I didn’t want to go through all the Google results, because most of those libraries have some dramatically different api than RecyclerView, so you need to take some real time to understand them.

What I found is those two libraries have features I want: SuperRecyclerView and UltimateRecyclerView. Let’s look at both of them

SuperRecyclerView

This library is well documented, have nice architecture and good method names. But there’s two things that turned me off from it.

First: empty text view is triggered when you don’t set adapter and not when adapter item count is 0, when it’s 0 – you don’t see no empty text view, which is weird. Second: ProgressBar footer is not a footer, like you have in all the app out there, but an overlaying view over the bottom, which looks ugly

UltimateRecyclerView

This library has the most stars out there and bunch of different features. But it’s not well documented and architecture itself is ugly, method names aren’t clear. Plus I lost trust completely to it when I saw class names starting lower case and method names lower case with underscore like it’s Python or something.

Creating Your Own Library

So when you want some simple stuff – it’s much easier and faster to implement it yourself, then spend hours understanding some bad libraries/forking them, modifying. Plus I like my own code over other’s in most cases, so let’s do it

I wanted it to be as close to RecyclerView library as possible. I think it’s good and clean. Many people like reinventing the wheal in software, especially when you look at JS frameworks, I think it’s a waste of people’s life to force them to

Let’s learn one more way how to do the same thing in a different way

Rather then learn something actually new. So this library will have the easiest learning process – you won’t have to spend hours.

Setup

Add this library to dependencies

Instead of RecyclerView in XML you declare SimpleRecyclerView. ViewHolder is implemented the same way as before.

and adapter needs to extend SimpleRecyclerView.Adapter

That’s it, everything else is same, you set LayoutManager etc. As you see, adapter methods have different names than in RecyclerView.Adapter, I decided to hide item holder type for easier footer progress integration, you’ll see.

Show Nothing Found View

This view you want to display when there’s no stuff in the list, something like “Nothing found”. It’s disabled by default. To enable it you just create a layout something like this

and then set it with app:empty_layout attribute

Nothing else is needed

Pagination

Here what I want is to show footer ProgressBar at the bottom of the list and have a fetch more listener which is triggered when you reach near the end of current list. Pagination is disabled by default. Look at the solution I came up with

That’s all, what you’ll get is this

simplest android recyclerview library

 

Listener is triggered each time you reach the bottom of the list and ProgressBar shown, if you setOnLoadMoreListener.

As you know, you need to notifyDataSetChanged() after adding stuff to your list or more optimized – notifyItemRangeInserted() so you don’t touch previous items, but only newly added.

With SimpleRecyclerView#setDoneFetching you get notifyItemRangeInserted() implemented for you, you don’t need to worry about no indexes or number of items inserted

And in case if there’s no more stuff from your server and you don’t want to display ProgressBar footer any more – call this method

You won’t see ProgressBar from that point

Custom ProgressBar Footer

If you want your own progress bar footer – you can declare it with this attribute

 

Just Beginning

So obviously it’s not nearly as many features as UltimateRecyclerView has, but I like it more already. I will be implementing more features, like I’ve just realized that initial ProgressBar is just as important. Check library repo here, it has a sample app there

Check this post if you want to learn how to upload your own library to jCenter

 

 

 


  • André Luiz Reis

    Thanks for sharing your experience with RecyclerView. I started to use now the UltimateRecyclerView and it’s not easy. But it’s attractive because it has many features.