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 - vinc3m1/DragSortAdapter: Drag and drop re-ordering adapter for RecyclerView

This repository was archived by the owner on May 9, 2021. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

70 Commits
70 Commits

Folders and files

NameName
Last commit message
Last commit date
dragsortadapter
dragsortadapter
 
 
example
example
 
 
gradle/wrapper
gradle/wrapper
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.txt
LICENSE.txt
 
 
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

DragSortAdapter

Maven Central Android Arsenal

Drag and Drop adapter implementation for RecyclerView. Targeted to support any LayoutManager and ItemAnimator.

Note: This is an advanced library meant to be flexible and customizable which leads to more complexity in integration. It is not meant to be a simple drop-in. If you need even more customization I suggest exploring the source and copying relevant code that you need.

Usage

Add Snapshot repository and add to dependencies:

dependencies {
  compile 'com.makeramen:dragsortadapter:X.X.X'
}

Override DragSortAdapter<T extends DragSortAdapter.ViewHolder>, see ExampleAdapter.java: required functions:

// this function should be reasonable performant as it gets called a lot on the UI thread
public abstract int getPositionForId(long id);
  
// this needs to re-order the positions **live** during dragging
public abstract boolean move(int fromPosition, int toPosition);

// not required but you probably want to override this to save the re-ordering after drop event
public void onDrop() { }

Set adapter in code:

recyclerView.setAdapter(new ExampleAdapter(recyclerView));

Call startDrag() when you want to start dragging (e.g. onLongClick):

    @Override public boolean onLongClick(@NonNull View v) {
      startDrag();
      return true;
    }

Works with any LayoutManager

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));

And any ItemAnimator:

recyclerView.setItemAnimator(new DefaultItemAnimator());

About

Drag and drop re-ordering adapter for RecyclerView

Resources

Readme
License
Activity

Stars

519 stars

Watchers

1 watching

Forks

71 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — 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.