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:
public class MyViewHolder extends SwiperooViewHolder<String> {
static class Factory implements SwiperooViewHolder.Factory {
@Override
public SwiperooViewHolder createViewHolder(Context context, ViewGroup parent, int viewType) {
return new MyViewHolder(from(context).inflate(YOUR_ITEM_LAYOUT, parent, false), context);
}
}
public MyViewHolder(View itemView, Context context) {
super(itemView, context);
}
@Override
public void bindViewHolder(String data) {
}
}
Pay attention to the Factory class, you need to return an instance of your ViewHolder (Factory pattern)
public class MyAdapter extends SwiperooAdapter<String> {
public MyAdapter(Context context, List<String> items, Listener listener, SwiperooViewHolder.Factory factory) {
super(context, items, listener, factory);
}
}
mSwiperooRecyclerView.setLayoutManager(new LinearLayoutManager(this));
MyAdapter adapter = new MyAdapter(this, items, this, new MyViewHolder.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
@Override
public void onItemDeleted(String item) {
///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.