DNDGridView


Source link: https://github.com/SpongeBobSun/DNDGridView

DNDGridView

Drag & Drop GridView on Android.

Poject Components

DNDGridView provide below components.

  • DNDGridView, which is a customized GridView.
  • DNDAdapter, most of the drag & drop part is done in this file.
  • DNDViewHolder, provide ViewHolder which can save current view's position.

Project Structure

After checkout this repo, you will get a sample project and the DNDGridView module is located in dndgridview folder.

Usage

To use DNDGridView, you need to add it in layout xml file or Java code.

<sun.bob.dndgridview.DNDGridView
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1.0"
  android:id="@+id/id_dndgridview"/> 

DNDGridView has some restrictions which currently I didn't find a better way to bypass.

First, DNDGridView widget only accept DNDAdapter as it's adapter. It will check adapter's type while calling setAdapter. If it's not an instance of DNDAdapter, it will throw a big IllegalArgumentException.

So, to use drag & drop feature, you need to extend DNDAdapter using your own adapter. You can using sample project as reference.

In short word, you must extends DNDAdapter, you MUST implement getView function, you MUST call setUpDragNDrop after you are done with your item view.


  ((DNDGridView) findViewById(R.id.id_dndgridview)).setAdapter(new DNDAdapter(this, R.layout.dnd_item) {

ArrayList data;

{

 data = new ArrayList();

 for (int i = 0; i < 100; i++) {

  data.add("" + i);

 
}

 this.setCustomArray(data);

 
}

@Override

public View getView(int posistion, View convertView, ViewGroup parent) {

 View ret = convertView;

 ViewHolder tag;

 if (convertView == null) {

  ret = View.inflate(getContext(), R.layout.dnd_item, null);

  tag = new ViewHolder(posistion);

  tag.imageView = (ImageView) ret.findViewById(R.id.id_imageview);

  tag.textView = (TextView) ret.findViewById(R.id.id_textview);

  ret.setTag(tag);

 
}
 else {

  tag = (ViewHolder) ret.getTag();

 
}

 tag.imageView.setImageResource(R.drawable.img0);

 tag.textView.setText((String) data.get(posistion));

 setUpDragNDrop(posistion,ret);

 return ret;

}

  
}
);
 

Second, DNDGridView require a DNDViewHolder as view holder. So, if you are using your own viewholder, please extend DNDViewHolder to get this module working. If you didn't specified a view holder, DNDAdapter will automaticlly add one for you.

In short word, your view holder MUST extends DNDViewHolder

class ViewHolder extends DNDViewHolder {
  public ViewHolder(int posistion){

super(posistion);
  
}
  Object data;  ImageView imageView;  TextView textView; 
}
 

Screenshot

Picture file size is 1.6MB so you may want to get yourself a cup of coffee while it's loading.

Resources

A showcase of RxJava and Model View Presenter, plus a number of other popular libraries for android development, including AutoValue, Retrofit, Moshi, and ButterKnife. Unit tests covering any business logic and Robolectric tests verifying the ui.

Converts a string to a slug.

A JUnit rule which allows unit testing of custom Lint rules.

A notification badge with animation.

This plugin helps to develop with Android Data Binding Library.

VoronoiView is a view (ViewGroup) that allows you to add and display views inside Voronoi diagram regions.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes