How to catch a View with Tag by Espresso in Android?
<p>I have a <code>PinCodeView</code> that extends <code>LinearLayout</code>. I have following code in my <code>init()</code> method. <code>DigitEditText</code> extends <code>EditText</code> and just accepts one digit. This view will be used to receive confirmation code which has 4 digits long.</p>

<pre><code>private void init()
{
    ...

    for (int i = 0; i &lt; 4; i++)
    {
        DigitEditText digitView = getDigitInput();
        digitView.setTag(R.id.etPinCodeView, i); // uses for Espresso testing
        digitView.setKeyEventCallback(this);
        ...
}
</code></pre>

<p>I have created <code>res/values/ids.xml</code> and this is its content:</p>

<pre><code>&lt;resources&gt;
    &lt;item name="etPinCodeView" type="id"/&gt;
&lt;/resources&gt;
</code></pre>

<p>Now, in Espresso I want to catch each <code>DigitEditText</code> and put a digit in it. How I'm able to do that? I see there are two methodes, <code>withTagKey()</code> and <code>withTagValue()</code> but I have no idea how to get them into work.</p>

<p>I thought something like this might work but seems I'm not able to assign 0 into <code>withTagValue()</code>.</p>

<pre><code>onView(allOf(withTagKey(R.id.etPinCodeView), withTagValue(matches(0)))).perform(typeText("2"));
</code></pre>