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 — DragSortAdapter/README.md at main · vinc3m1/DragSortAdapter

This repository was archived by the owner on May 9, 2021. It is now read-only.

Expand file tree

/

README.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
58 lines (46 loc) · 2.27 KB
/

README.md

Copy path

File metadata and controls

58 lines (46 loc) · 2.27 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

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());
You are visitor 01402792 — 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.