Android Programming: The Big Nerd Ranch Guide, 2nd Edition
by Bill Phillips, Chris Stewart, Brian Hardy, Kristin Marsicano
Responding to Presses
As icing on the RecyclerView cake, CriminalIntent should also respond to a press on these list items. In Chapter 10, you will launch the detail view for a Crime when the user presses on that Crime in the list. For now, show a Toast when the user takes action on a Crime.
As you may have noticed, RecyclerView, while powerful and capable, has precious few real responsibilities. (May it be an example to us all.) The same goes here: handling touch events is mostly up to you. If you need them, RecyclerView can forward along raw touch events. Most of the time, though, this is not necessary.
Instead, you can handle them like you normally do: by setting an OnClickListener. Since each View has an associated ViewHolder ...
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