Visit GitHub Repo
List View Sections

PinnedRecyclerView Android library

This library allows you to create a list of items that are pinned by a floating label (text or image) on the left of the list .

PinnedRecyclerView in action

Demo Text Pinned

Demo Image Pinned


Add library


compile 'com.gvillani:pinnedlist:0.9.2'



Pinned Text List

Add the PinnedListLayout in your Layout.


Get a reference to the PinnedLayout and get the RecyclerView that it contains.

mListLayout = (PinnedListLayout)findViewById(;
mRecyclerView = mListLayout.getRecyclerView();

Create a GroupListWrapper with the static method createAlphabeticList(). You can also create it manually managing each group, but if you want a simple alphabetically ordered list using create createAlphabeticList() is the fastest way.

GroupListWrapper listGroup = GroupListWrapper.createAlphabeticList(contacts, GroupListWrapper.ASCENDING);

And finally instantiate your custom Adapter (it must extend PinnedAdapter) and set it to the RecyclerView

mListAdapter = new ContactAdapter(this, listGroup, mListLayout);

Moreover, if you want create a GroupListWrapper using the createAlphabeticList you need to tell the system which label will be applied for your object and the related order. For example if you have a Contact object that contains name and surname you can do something like this:

public class Contact implements GroupListWrapper.Selector{
    private String name;
    private String surname;

    public String select() {
        return name+surname;

In this way you are telling the system that you want that your pin label will have the first letter of the name and they should be ordered using the name and the surname (if the name is the same).

Pinned Image List

In order to use a pinned list with image you need to set in your layout:


You create your GroupListWrapper

GroupListWrapper listGroup = new GroupListWrapper();

Then you need to create a list of wrapping object (ItemPinned) that contain your costom object (for example a Contact) and then you add

ItemPinned itemD1 = new ImageItemPinned(new Contact("Ben","Weber", R.drawable.contact1)); 
ItemPinned itemD2 = new ImageItemPinned(new Contact("Emma","Hartmann", R.drawable.contact9)); 

List<ItemPinned> listD = new ArrayList<>();

Group groupD = new Group(listD, R.drawable.germany);

And eventually you add one or more Group object to the GroupListWrapper


Finally instantiate your custom Adapter (it must extend PinnedAdapter) and set it to the RecyclerView

mListAdapter = new ContactAdapter(this, listGroup, mListLayout);

The Adapter

As before mentioned, you need to create your custom Adapter extending PinnedAdapter class.

When you override the method onCreateViewHolder you need to create your custom row layout (for example using inflater) and then you need to allow the system to wrap that layout inside a layout that contains the pin. So, you simply need to obtain a wrapped version of your layout passing it to getRowLayout() as shown in the example below:

public PinnedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = mLayoutInflater.inflate(R.layout.item_contact, parent, false);
    ViewHolderContact viewHolderContact = new ViewHolderContact(getRowLayout(view));
    return viewHolderContact;


Currently the Library is created as a compound View wrapped inside a CoordinatorLayout. So, if you need to use a CoordinatorLayout you can use it: for example you can add a Toolbar inside it, or a FAB that will be automatically coordinated with the Snackbar.

The library support only the LinearLayoutManager, so if you try to set a different layout it will be ignored.


  • Allow the user to manipulate the content of the adapter without replacing the entire dataset.
  • Support for GridLayoutManager
  • Find different strategy that make the wrapping of the custom layout inside the pinner layout more transparent (user should not call getRowLayout() from his adapter)
  • Allow groups manipulation

Become Pro in Android by watching videos