So, you may be trying to set up a
RecyclerView that has different
ViewHolders. For instance, a
Post object that could have a picture or might be just text with different
ViewHolders for each case.
While the code in the guide covers that scenario, we are going to take it a step further and also tackle a slightly different problem. Our goal is to add objects of different types to a single
RecyclerView in a simple to implement and easy to manage way.
We have three objects:
Newspaper. We want to display them in one…
Swipe to delete is a prevailing paradigm users are accustomed to on mobile platforms. Adding this functionally is a good way to get your app in line with modern design practices. While there are many libraries that will accomplish this for us, subsequently adding extra bulk to our code, implementing it ourselves is not that complicated. So, let’s get started.
To implement swipe to delete and undo in our
RecyclerView we are going to need 3 key components:
ItemTouchHelper: This attaches to the
RecyclerViewand watches for swipes.
ItemTouchHelper.SimpleCallback: This is passed into
ItemTouchHelper’s constructor and contains the code that…