GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - inloop/SimpleRecyclerAdapter: A simple and reusable RecyclerView adapter

BranchesTags
Open more actions menu

Latest commit

 

History

43 Commits
43 Commits

Folders and files

NameName
Last commit message
Last commit date
gradle/wrapper
gradle/wrapper
 
 
library
library
 
 
sample
sample
 
 
website
website
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

SimpleRecyclerAdapter

Writing a RecyclerView adapter is a lot of boiler-plate code that is doing the same thing in most cases. This library provides you an universal SimpleRecyclerAdapter, which you can use directly. You can bind any list of arbitrary objects. The adapter was implemented with performance in mind. No new objects are created during the binding process (except for the first visible rows and then the objects are reused).

How to implement

Very easy, to create a new RecyclerViewAdapter, you only need to make an instance of our SimpleRecyclerAdapter (you don't need to extend this class):

mRecyclerAdapter = new SimpleRecyclerAdapter<>(mOnClickListener, new SimpleRecyclerAdapter.CreateViewHolder<MyDataObject>() {
        @Override
        public SettableViewHolder<MyDataObject> onCreateViewHolder(final ViewGroup parent, final int viewType) {
            return new MyDataViewHolder(BasicAdapterActivity.this, R.layout.item_mydata, parent);
        }
});

Then create a standard ViewHolder, extending SettableViewHolder. You only need to implement the setData() method.

public class MyDataViewHolder extends SettableViewHolder<MyDataObject> {

    // constructor omitted

    @Override
    public void setData(@NonNull MyDataObject data) {
        mTitle.setText(data.getTitle());
        mDescription.setText(data.getText());
    }
}

There is also support for multiple clickable areas (see AdvancedDataViewHolder example), multiple view-types, long-press.

Advanced use-case

Take a look at the sample AdvancedAdapterActivity.

The code to achieve this:

@Override
public void onItemClick(@NonNull WrappedMyDataObject item, @NonNull SettableViewHolder<WrappedMyDataObject> viewHolder, @NonNull View view) {
    if (item.getType() == WrappedMyDataObject.ITEM_TYPE_NORMAL) {
        MyDataObject dataObject = item.getDataObject();
        int itemPos = viewHolder.getAdapterPosition();

        switch (view.getId()) {
            case R.id.btn_more:
                setTitle("Action clicked on item: " + dataObject.getTitle());
                break;
            case R.id.btn_remove:
                mRecyclerAdapter.removeItem(item, true);
                break;
            case R.id.btn_move_up:
                mRecyclerAdapter.swapItem(itemPos, Math.max(0, itemPos - 1), true);
                break;
            case R.id.btn_move_down:
                int maxIndex = mRecyclerAdapter.getItemCount() - 1;
                mRecyclerAdapter.swapItem(itemPos, Math.min(maxIndex, itemPos + 1), true);
                break;
            default:
                //Actual item click
                setTitle("Last clicked item: " + dataObject.getTitle());
                break;
        }
    }
}

Download

Grab via Gradle:

compile 'eu.inloop:simplerecycleradapter:0.3.4'

About

A simple and reusable RecyclerView adapter

Resources

Readme
License
Activity
Custom properties

Stars

41 stars

Watchers

6 watching

Forks

9 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.