An extandable adapter which provides swipe to delete on your row item.
Inspired by: https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete
Add Gradle dependency:
dependencies {
compile 'us.belka:swiperoo-library:1.0.0'
}<dependency>
<groupId>us.belka</groupId>
<artifactId>swiperoo-library</artifactId>
<version>1.0.0</version>
<type>pom</type>
</dependency>In the app folder you will find a working example of the library
You need to do 3 things to make the library works:
publicclassMyViewHolderextendsSwiperooViewHolder<String> {
staticclassFactoryimplementsSwiperooViewHolder.Factory {
@OverridepublicSwiperooViewHoldercreateViewHolder(Contextcontext, ViewGroupparent, intviewType) {
returnnewMyViewHolder(from(context).inflate(YOUR_ITEM_LAYOUT, parent, false), context);
}
}
publicMyViewHolder(ViewitemView, Contextcontext) {
super(itemView, context);
}
@OverridepublicvoidbindViewHolder(Stringdata) {
}
}Pay attention to the Factory class, you need to return an instance of your ViewHolder (Factory pattern)
publicclassMyAdapterextendsSwiperooAdapter<String> {
publicMyAdapter(Contextcontext, List<String> items, Listenerlistener, SwiperooViewHolder.Factoryfactory) {
super(context, items, listener, factory);
}
}mSwiperooRecyclerView.setLayoutManager(newLinearLayoutManager(this));
MyAdapteradapter = newMyAdapter(this, items, this, newMyViewHolder.Factory());
mSwiperooRecyclerView.setAdapter(adapter);
adapter.addSupportToSwipeToDelete(this, mSwiperooRecyclerView);You can use "this" as third parameter in the Adapter or you can directly pass in an implementation of the Listener, both ways you will implement the interface to handle item delete
@OverridepublicvoidonItemDeleted(Stringitem) {
///Do your stuff with the deleted item
}Your item layout container must be a Relative Layout, otherwise the Holder will throw you a NotSupportedException
Swiperoo is Copyright (c) 2017 Belka, srl. It is free software, and may be redistributed under the terms specified in the LICENSE file.
Belka is a Digital Agency specialized in design, mobile applications development and custom solutions. We love open source software! You can see our projects or look at our case studies.
Interested? Hire us to help build your next amazing project.
