O'Reilly logo

Android 5 Programming by Example by Kyle Mew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Responding to the RecyclerView selections

Having successfully produced a RecyclerView, and populated it with CardViews containing our data, we need to be able to select individual items and do something with them. Next, we will provide the RecyclerView with a click listener and add a new Activity that will present our records in greater detail on a separate screen.

Creating the OnClickListener

Before we create our new Activity, we need an OnClickListener that can tell which CardView was clicked on. Here's how it's done:

  1. Open the MainActivity class.
  2. Add the following class member:
    static View.OnClickListener mainOnClickListener;
  3. Assign the listener in the onCreate() method like this:
    mainOnClickListener = new MainOnClickListener(this);
  4. Create the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required