Skip to content

sadedil/SectionedRecyclerViewAdapter

Repository files navigation

Sectioned Recycler View Adapter

SectionedRecyclerViewAdapter offers a simple way to create RecyclerView adapters for Xamarin Android.

Under the hood

This library has only one class inherits from Android's RecyclerView.Adapter.

In this class, these original methods are hidden:

override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)

override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)

Instead of overriding original RecyclerView.Adapter methods, you have to override these new (much simpler) methods, similar to iOS's TableView DataSource:

///How many sections do you have?
virtual int NumbersOfSections();

///How many items do you have in this specified section?
abstract int RowsInSection(int section);

///How to inflate Item Views?
abstract RecyclerView.ViewHolder OnCreateItemViewHolder(ViewGroup parent);

///How to populate Item Views?
abstract void OnBindItemViewHolder(RecyclerView.ViewHolder holder, IndexPath indexPath);

///How to inflate Section Views? (optional)
virtual RecyclerView.ViewHolder OnCreateSectionViewHolder(ViewGroup parent);

///How to populate Section Views? (optional)
virtual void OnBindSectionViewHolder(RecyclerView.ViewHolder holder, int section);

///How to get item at this indexPath
abstract T GetItem(IndexPath indexPath);

Why use this library? How it makes things easy?

Because, it addresses item positions in custom IndexPath structure. It's easy to know, which element is in which section?

class IndexPath
{
    int OriginalPosition { get; set; }
    int SectionIndex { get; set; }
    int? ItemIndex { get; set; }
}

How can i use?

In the solution, you can find a demo project. It has two examples filled with comments. First one is a basic example with minimum requirements, other one is slightly advanced.

I think this demo project is enough for understanding the logic of this library.

Any screenshots?

You can find demo screen recordings below

Demo

About

SectionedRecyclerViewAdapter offers a simple way to create RecyclerView adapters for Xamarin Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages