I want my RecyclerView Item swipe left and there must be shown star-styled checkBox to add to favorites list. I am using FastAdapter by Mike Penz. How can I do that?
1 Answers
The following question is not related to the adapter implementation. The main purpose of the Adapter
itself is to provide the items. In the FastAdapter
for example the adapter is completely independent of any UI. and will only handle abstract elements.
It's the View
s job to define how an item will look like and behave. As such this is completely up to the developer, and all flexibility is given.
For showcase purposes such a case was implemented in the sample app of the FastAdapter
.
You will need to attach an ItemTouchHelper.SimpleCallback
to the RecyclerView
which will handle the swipe action of the user.
With the provided util classes this is done like this:
touchCallback = new SimpleSwipeDragCallback(
this,
this,
leaveBehindDrawableLeft,
ItemTouchHelper.LEFT,
ContextCompat.getColor(this, R.color.md_red_900)
)
.withBackgroundSwipeRight(ContextCompat.getColor(this, R.color.md_blue_900))
.withLeaveBehindSwipeRight(leaveBehindDrawableRight);
touchHelper = new ItemTouchHelper(touchCallback); // Create ItemTouchHelper and pass with parameter the SimpleDragCallback
touchHelper.attachToRecyclerView(recyclerView); // Attach ItemTouchHelper to RecyclerView
You can find the full sample source code here: https://github.com/mikepenz/FastAdapter/blob/develop/app/src/main/java/com/mikepenz/fastadapter/app/SwipeListActivity.java#L120

- 12,708
- 14
- 77
- 117
-
Your support is greatly appreciated. – Dilshodbek Jumaboev Oct 15 '18 at 10:14