Responding to Presses

As icing on the RecyclerView cake, CriminalIntent should also respond to a press on these list items. In Chapter 12, 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. But most of the time this is not necessary.

Instead, you can handle them like you normally do: by setting an OnClickListener. Since each View has an associated ViewHolder, you ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.