title: Android - espresso - clicking on a listview entry based on custom objects
body: <p>Espresso is used for automatic testing my App. </p>
  
  <p>Edit: below you find a number of answers!</p>
  
  <p>How can I click (within an automated Espresso test script) on an entry in a long list of custom objects? </p>
  
  <p>In the Espresso documentation there is an example of a LongList. Working with a List of objects is what I normally do. Trying many options to step from Map to Object didn't yield good results so far. </p>
  
  <p>The Espresso documentation says a 'onData' should be used. So, something like: </p>
  
  <pre><code>onData( myObjectHasContent("my_item: 50")).perform(click());
  onView(withId( R.id.selection_pos2)).check(matches(withText("50")));
  </code></pre>
  
  <p>My questions (and I think they are helpful for the learning community): 
   - Can you write a good Matcher for this?
   - How can we use that in the 'onData' ?</p>
  
  <p>What is the situation? On the screen I have a listview of objects like: </p>
  
  <pre><code>public class MyOjbect { 
      public String content; 
      public int    size; 
  }
  </code></pre>
  
  <p>The adapter I use to populate the populated list is: </p>
  
  <pre><code>public class MyObjectWithItemAndSizeAdapter extends ArrayAdapter&lt;MyObjectWithItemAndSize&gt; {
      private final Context context;
      private final List&lt;MyObjectWithItemAndSize&gt; values;
      ...
      @Override
      public View getView(int position, View concertView, ViewGroup parent) {
          View view = null;
          if (concertView != null) {
              view = (LinearLayout) concertView;
          } else {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              view = inflater.inflate( R.layout.list_item, parent, false);
          } 
          TextView itemT = (TextView) view.findViewById( R.id.item_content);
          itemT.setText( values.get(position).item);
          TextView sizeT = (TextView) view.findViewById( R.id.item_size);
          sizeT.setText( "" + values.get(position).size);
          return view;
      }
   }
  </code></pre>