Android Programming: The Big Nerd Ranch Guide, Third Edition
by Bill Phillips, Chris Stewart, Kristin Marsicano
Binding List Items
Binding is taking Java code (like model data in a Crime, or click listeners) and hooking it up to a widget. So far, in all the exercises up until this point in the book, you bound each and every time you inflated a view. This meant there was no need to split that work into its own method. However, now that views are being recycled, it pays to have creation in one place and binding in another.
All the code that will do the real work of binding will go inside your CrimeHolder. That work starts with pulling out all the widgets you are interested in. This only needs to happen one time, so write this code in your constructor.
Listing 8.21 Pulling out views in the constructor (CrimeListFragment.java)
private class ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access