title: Espresso - Click by text in List view
body: <p>I am trying to click on a text in a list view using Espresso. I know they have <a href="https://code.google.com/p/android-test-kit/wiki/EspressoSamples#Matching_data_using_onData_and_a_custom_ViewMatcher">this guide</a>, but I can't see how to make this work by looking for text.  This is what I have tried</p>
  
  <blockquote>
  <pre><code>Espresso.onData(Matchers.allOf(Matchers.is(Matchers.instanceOf(ListView.class)), Matchers.hasToString(Matchers.startsWith("ASDF")))).perform(ViewActions.click());
  </code></pre>
  </blockquote>
  
  <p>As expected, this didn't work. The error said no view in hierarchy. Does anyone know how to select a String? (<code>"ASDF"</code> in this case) Thanks in advance.</p>
  
  <h2>Update due to @haffax</h2>
  
  <p>I received error:</p>
  
  <blockquote>
    <p>com.google.android.apps.common.testing.ui.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.</p>
  </blockquote>
  
  <h2>Second error</h2>
  
  <p>With this code</p>
  
  <blockquote>
  <pre><code>onData(hasToString(startsWith("ASDF"))).inAdapterView(withContentDescription("MapList")).perform(click());
  </code></pre>
  </blockquote>
  
  <p>I get this error</p>
  
  <blockquote>
    <p>com.google.android.apps.common.testing.ui.espresso.PerformException: Error performing 'load adapter data' on view 'with content description: is "MapList"'.</p>
    
    <p>Caused by: java.lang.RuntimeException: No data found matching: asString(a string starting with "ASDF") </p>
  </blockquote>
  
  <hr>
  
  <h2>Solution</h2>
  
  <blockquote>
    <p>onData(anything()).inAdapterView(withContentDescription("desc")).atPosition(x).perform(click())</p>
  </blockquote>