SuperAdapter


Source link: https://github.com/chenenyu/SuperAdapter

Chinese Version ???

QQ??271849001(?)

SuperAdapter

Adapter(ListAdapter, RecyclerView.Adapter) wrapper for android.

Less code for redundant adapter. You won't need to write ViewHolder, createView, setTag, getTag, and confuse how to setOnItemClickListener to RecyclerView, etc. The only thing you really need to do is that implement a method onBind().

Android Studio:

In build.gradle:

compile 'com.android.support:recyclerview-v7:...' ... compile 'org.byteam.superadapter:superadapter:x.y.z'

Current latest version:

Eclipse:

Add latest Jar to libs dir manually.

Features

  • Less code!
  • Header and footer.
  • OnItemClickListener and OnItemLongClickListener.
  • Hide view holder.
  • Supports both BaseAdapter and RecyclerView.Adapter.
  • Wraps CRUD.
  • Loading animation supporting!

How to use

Simple adapter

public class SingleAdapter extends SuperAdapter<String> {
  public SingleAdapter(Context context, List<String> list, int layoutResId) {

super(context, list, layoutResId);
  
}

@Override  public void onBind(SuperViewHolder holder, int viewType, int position, String item) {

holder.setText(R.id.tv_name, item);
  
}
 
}
 

Then:

mSingleAdapter = new RecyclerSingleAdapter(getContext(), names, R.layout.your_item);

recyclerView.setAdapter(mSingleAdapter);
 

Multiple item types adapter

public class MultipleAdapter extends SuperAdapter<MockModel> {
  public MultipleAdapter(Context context, List<MockModel> list, IMulItemViewType<MockModel> multiItemViewType) {

super(context, list, multiItemViewType);
  
}

@Override  public void onBind(SuperViewHolder holder, int viewType, int position, MockModel item) {

switch (viewType) {

 case 0:
  holder.setText(R.id.tv_name, item.getName());

  break;
 case 1:
  holder.setText(R.id.tv_name, item.getName());

  holder.setImageResource(R.id.iv_portrait, R.mipmap.ic_launcher);

  holder.setText(R.id.tv_age, String.valueOf(item.getAge()));

  break;

}
  
}
 
}
 

Then:

multiAdapter = new MultipleAdapter(getContext(), models, new IMulItemViewType<MockModel>() {
  @Override  public int getItemViewType(int position, MockModel mockModel) {

if (position % 2 == 0) {

 return 0;

}

return 1;  
}

@Override  public int getLayoutId(int viewType) {

if (viewType == 0) {

 return R.layout.item_type1;

}

return R.layout.item_type2;  
}

@Override  public int getViewTypeCount() {

return 2;  
}
 
}
);
 recyclerView.setAdapter(mMultiAdapter);
 

If you don't want to offer IMulItemViewType when creating adapter, you can override offerMultiItemViewType() in adapter:

@Override protected IMulItemViewType<MockModel> offerMultiItemViewType() {
  return new IMulItemViewType<MockModel>() {

@Override
public int getViewTypeCount() {

  return 2;

}

 @Override
public int getItemViewType(int position, MockModel mockModel) {

 if (position % 2 == 0) {

  return 0;
 
}

 return 1;

}

 @Override
public int getLayoutId(int viewType) {

 if (viewType == 0) {

  return R.layout.item_type1;
 
}

 return R.layout.item_type2;

}
  
}
; 
}
 

Then:
multiAdapter = new MultipleAdapter(getContext(), models, null);
If using RecyclerView, you can also use class SimpleMulItemViewType:

mAdapter = new MultipleAdapter(getContext(), models, new SimpleMulItemViewType<MockModel>() {
  @Override  public int getItemViewType(int position, MockModel mockModel) {

if (position % 2 == 0) {

 return 0;

}

return 1;  
}

@Override  public int getLayoutId(int viewType) {

if (viewType == 0) {

 return R.layout.item_type1;

}

return R.layout.item_type2;  
}
 
}
);
 recyclerView.setAdapter(mAdapter);
 

Load animation:

Open default animation:
adapter.enableLoadAnimation();
or
adapter.enableLoadAnimation(long duration, new SlideInBottomAnimation());
if you want to show animation when item shows each time:
adapter.setOnlyOnce(false);
Note that you can set custom animation by implementing BaseAnimation.

Welcome to submit PRs and open issues! : )

License

Copyright 2016 byteam.org.  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

Beautify your RecyclerViews with a great parallax effect !

Abstract, easy, quick, flexible and extendable Rapid Android development.

An Android module that makes WebRTC signaling easy!

A Java-language API for doing compile time or runtime code generation targeting the Dalvik VM. Unlike cglib or ASM, this library creates Dalvik .dex files instead of Java .class files.

A region under finger becomes transparent and shows the bottom part of the image layout area.

Hardware accelerated transcoder for Android, written in pure Java.

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