title: android espresso : total count of elements with same rid not in adapter view
body: <p>I am trying to get the count of elements with same rid</p>
  <p>The solutions here <a href="https://stackoverflow.com/questions/27430500/how-to-get-count-of-items-with-same-ids-which-are-not-in-adapter-view">How to get count of items with same ids which are not in adapter view</a> is not helping me.</p>
  <pre class="lang-java prettyprint-override"><code>static int counter = 0;
  public static Matcher&lt;View&gt; withIdAndDisplayed(final int id) {
      Checks.checkNotNull(id);
      return new TypeSafeMatcher&lt;View&gt;() {
          @Override
          public void describeTo(Description description) {
              description.appendText(&quot;with item id: &quot; + id);
          }
  
          @Override
          public boolean matchesSafely(View view) {
              if ((view.getId() == id) &amp;&amp; (view.getGlobalVisibleRect(new Rect())
                      &amp;&amp; withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE).matches(view))){
                  counter++;
                  return true;
              }
              return false;
          }
      };
  }
  </code></pre>