Android Design Patterns and Best Practice by Mew Kyle
Author:Mew, Kyle [Mew, Kyle]
Language: eng
Format: azw3, pdf
Publisher: Packt Publishing
Published: 2016-12-26T05:00:00+00:00
Adding swipe and dismiss actions
It is unlikely that we would need swipe and dismiss behavior in this particular app, as the lists are short and there is little to be gained by allowing users to edit them. However, so that we can see how this important and useful function is applied, we will implement it here even though we won't be including it in the final design.
Swiping, as well as dragging and dropping, is largely managed by the ItemTouchHelper, which is a type of RecyclerView.ItemDecoration. The callbacks provided for this class allow us to detect item movement and direction and to intercept these actions and respond to them in code.
As you can see here, there are just a few steps to implementing swipe and dismiss behavior:
Firstly, our list is now going to change length, so remove the line recyclerView.setHasFixedSize(true); or set it to false.
It is always a good idea to keep our onCreate() methods as simple as possible, as there can often be a great deal going on there. We will create a separate method to initialize our item touch helper and call it from onCreate(). Here is the method:private void initItemTouchHelper() { ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder viewHolder1) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { int position = viewHolder.getAdapterPosition(); adapter.removeItem(position); } }; ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); itemTouchHelper.attachToRecyclerView(recyclerView); }
Download
Android Design Patterns and Best Practice by Mew Kyle.pdf
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
Odoo 15 Development Essentials - Fifth Edition by Daniel Reis & Greg Mader(3338)
Odoo 15 Development Essentials by Daniel Reis(2814)
React Native - Building Mobile Apps with JavaScript by Novick Vladimir(2529)
Learning Angular - Second Edition by Christoffer Noring(2358)
Pride and Prejudice by Jane Austen(2349)
Mobile Forensics Cookbook by Igor Mikhaylov(2017)
Computers For Seniors For Dummies by Nancy C. Muir(1995)
Bulletproof Android: Practical Advice for Building Secure Apps (Developer's Library) by Godfrey Nolan(1872)
Android Development with Kotlin by Marcin Moskala & Igor Wojda(1797)
Building Android UIs with Custom Views by Raimon Ràfols Montané(1789)
1936941139 (N) by Bob Rosenthal(1731)
Building Progressive Web Apps: Bringing the Power of Native to the Browser by Ater Tal(1725)
Hands-On Internet of Things with MQTT by Tim Pulver(1706)
Android App Development by Franceschi Hervé J.;(1702)
Ember.js in Action by Joachim Haagen Skeie(1689)
Hands-On Design Patterns with React Native by Mateusz Grzesiukiewicz(1656)
