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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.