title: How can I get the CardView from a clicked widget?
body: <p>In an Android app I have a <code>RecyclerView</code> and a <code>CardView</code> with a layout like the following:</p>
  
  <pre><code>CardView
      |
      +-- LinearLayout (H)
             |
             +-- ImageView[onclick=advance]
             |
             +-- LinearLayout (V)
                     |
                     +-- TextView
                     |
                     +-- TextView
  </code></pre>
  
  <p>When a user clicks the <code>ImageView</code>, I want to call a method on the corresponding <code>Adapter</code> with the index of the clicked <code>CardView</code>. Using <code>RecyclerView.getChildPosition</code> I can get that index. <em>However</em>, the click handler for the <code>ImageView</code> gets a reference to the <code>ImageView</code>. Not the <code>CardView</code>.</p>
  
  <p>So my code currently looks like this:</p>
  
  <pre><code>public void advance(View v) {
      Log.v(TAG, String.format("Determining position of %s", v));
      // TODO this "getParent" daisy-chain is really ugly. There must be a better way!
      LinearLayout p1 = (LinearLayout) v.getParent();
      CardView p2 = (CardView) p1.getParent();
      int pos = mRecyclerView.getChildPosition(p2);
      mAdapter.advance(pos);
  }
  </code></pre>
  
  <p>This <em>works</em>, but is 100% coupled to the layout (not only structure, but also classes). If I change the layout, I need to change the code. Is there not a way to get directly at the <code>CardView</code>?</p>