Smart Recycler View is an android library project to help developers to use the recycler view implementation in an easy way.
- androidx.recyclerview:recyclerview:1.1.0-beta01
- androidx.legacy:legacy-support-core-utils:1.0.0
Set up the project dependencies. To use this library in your project:
(1) Use the GitHub source and include that as a module dependency by following these steps:
- Clone this library into a project named SmartRecyclerView, parallel to your own application project:
git clone https://github.com/baldapps/SmartRecyclerView.git- In the root of your application's project edit the file "settings.gradle" and add the following lines:
include ':smartrecyclerview'
project(':smartrecyclerview').projectDir = new File('../Smartrecyclerview/smartrecyclerview/')- In your application's main module (usually called "app"), edit your build.gradle to add a new dependency:
dependencies {
...
compile project(':smartrecyclerview')
}Now your project is ready to use this library
Smart Recycler view adds to the support library version:
- Add click and long listeners in an easy way using the recycler view
- Add drag and swipe interface
- Add the choice mode like a ListView, so you can use none, single, multi and multi modal Extend BaseViewHolder and RecyclerArrayAdapter in order to add your logic. Example and how to use the list:
publicclassMainActivityextendsActivityimplementsDragListener, SmartRecycleView.OnItemClickListener, MultiChoiceModeListener {
privateItemTouchHelpertouchHelper;
privateTouchHelperCallbackcallback;
@OverrideprotectedvoidonCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SmartRecycleViewlist = findViewById(R.id.list);
ArrayList<Item> items = newArrayList<>();
//add some stuff to items hereArrayAdapterTestadapter = newArrayAdapterTest(this, items);
adapter.setDragListener(this);
list.setChoiceMode(CheckableList.SINGLE);
list.setMultiChoiceModeListener(this);
callback = newTouchHelperCallback(adapter);
touchHelper = newItemTouchHelper(callback);
touchHelper.attachToRecyclerView(list);
list.setLayoutManager(newLinearLayoutManager(this));
list.setAdapter(adapter);
list.addOnItemClickListener(this);
}
@OverridepublicvoidonStartDrag(RecyclerView.ViewHolderviewHolder) {
touchHelper.startDrag(viewHolder);
}
@OverridepublicvoidonItemClick(RecyclerViewparent, ViewclickedView, intposition) {
Log.d("TAG", "item cliked at postion " + position);
}
@OverridepublicvoidonItemLongClick(RecyclerViewparent, ViewclickedView, intposition) {
Log.d("TAG", "item long cliked at postion " + position);
}
/* Action modes */@OverridepublicvoidonItemCheckedStateChanged(ActionModemode, intposition, longid, booleanchecked) {
}
@OverridepublicbooleanonCreateActionMode(ActionModemode, Menumenu) {
// Inflate a menu resource providing context menu itemsMenuInflaterinflater = mode.getMenuInflater();
inflater.inflate(R.menu.delete_command, menu);
callback.enableDrag(false);
returntrue;
}
@OverridepublicbooleanonPrepareActionMode(ActionModemode, Menumenu) {
returnfalse;
}
@OverridepublicbooleanonActionItemClicked(ActionModemode, MenuItemitem) {
switch (item.getItemId()) {
caseR.id.delete_device:
//do domething heremode.finish(); // Action picked, so close the CABreturntrue;
default:
returnfalse;
}
@OverridepublicvoidonDestroyActionMode(ActionModemode) {
callback.enableDrag(true);
}- If you find any issues with this library, please open a bug here on GitHub
See LICENSE
1.0.0
- First version