Giter Club home page Giter Club logo

android-sectioned-adapter's Introduction

Android Sectioned Adapter

Android Section Adapter allows you to easily create a RecyclerView.Adapter which will automatically sort your data into sections and add a header above each section.

You can use it with the provided header view:

alt text

Or you can use it with a custom header view that you specify:

alt text

Usage

Get it with Gradle

Add the dependency to your build.gradle file.

compile 'com.cardinalsolutions:android-sectioned-adapter:1.0.0'

Implement Categorizable

Your data object needs to implement Categorizable.getCategory() to return the name of its category. For each category name that appears in the data, SectionedAdapter will automatically create and insert a header view for that category and place all the item views beneath it. For example, the Dog class will be sectioned according to the breed of the dog.

class Dog implements Categorizable
{
    String name;
    String breed;

    public String getCategory()
    {
        return breed;
    }
}

The Person example is sectioned according to the first letter of his/her last name.

class Person implements Categorizable
{
    String firstName;
    String lastName;

    public String getCategory()
    {
        return lastName.substring(0, 1);
    }
}

Subclass SectionedAdapter

Sectioned Adapter takes care of generating and inserting the header views, so all your subclass needs to do is implement onCreateItemViewHolder() to create a ViewHolder for your items and onBindItemViewHolder() to bind the data, exactly like you would do when creating a normal RecyclerView.Adapter. SectionedAdapter takes type parameter, the type of your model object you want to adapt. Finally, you must call setListItems() with your list of Categorizable data in order to generate the headers and show your data.

Use a Custom Header View

Sectioned Adapter will automatically generate a header view for your data using a built-in layout as seen in the Yankees example above. You can also specify an XML layout that you want to inflate for each header. The view must contain a Text View with the ID @android:id/title.

android-sectioned-adapter's People

Contributors

axemorgan avatar

Watchers

Vijayaraj Sekar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.