Giter Club home page Giter Club logo

recyclerviewadapter's Introduction

RecyclerViewAdapter

Base implementation of RecyclerViewAdapter that avoids the need to directly build your own adapter.

Overview

This project is mostly proof of concept and updates may include breaking changes.

Usage

This project currently uses Git for distribution, so you'll need JitPack.

repositories {
  maven { url 'https://jitpack.io' }
}

Then just add this dependency to your project.

dependencies {
  compile 'com.github.moltendorf:RecyclerViewAdapter:0.4'
}

Now you can import the class anywhere in your project.

import net.moltendorf.android.recyclerviewadapter.RecyclerViewAdapter;

Create your view holders and data models.

package com.example;

import android.content.Context;
import android.view.ViewGroup;

import net.moltendorf.android.recyclerviewadapter.RecyclerViewAdapter;

public class ExampleViewHolder extends RecyclerViewAdapter.ViewHolder<ExampleData> {
  public ExampleViewHolder(Context context, ViewGroup viewGroup) {
    super(context, viewGroup, android.R.layout.simple_list_item_1);
  }

  @Override
  public void bindTo() {
    ((TextView) itemView).setText(object.getText());
  }

  public static class Factory extends RecyclerViewAdapter.Factory<ExampleViewHolder> {
    @Override
    public ExampleViewHolder createViewHolder(Context context, ViewGroup parent) {
      return new ExampleViewHolder(context, parent);
    }
  }
}

public class ExampleData {
  private String text = "Example Text";
  
  public String getText() {
    return text;
  }
}

Then just create a new RecyclerViewAdapter and bind your view holders to it.

// Create some example data.
List exampleList = new ArrayList(1);
exampleList.add(new ExampleData());

RecyclerViewAdapter adapter = new RecyclerViewAdapter(getContext());
adapter.setViewHolders(ExampleViewHolder.class);
adapter.changeDataSet(exampleList);

Code Style

This project is indented with 2 spaces and wraps after the 128th column for all code files. All files must end with a newline.

Why spaces? GitHub uses 8 spaces per tab in code previews which would cause code to show up differently.

Why 128 columns? Because at 10pt font, you can fit three files on a 2560x1440 monitor. Also, GitHub code viewer.

recyclerviewadapter's People

Contributors

maezred avatar

Watchers

James Cloos avatar  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.