Access text in dynamically generated TextView by ContextMenu
<p>I am currently trying to develop some sort of user profile in an app for android 4.0. In this activity I am adding an undefined number of fields of the following type. Now I want to add a context menu to all the fields and access the text on both fields in this pair, no matter which one was long-clicked.</p>

<pre><code>&lt;GridLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnCount="2"
    android:orientation="horizontal"
    android:rowCount="1" 
    android:paddingLeft="5dp"&gt;

    &lt;TextView
        android:id="@+id/subscriberFieldTextPrefix"
        android:layout_column="0"
        android:layout_gravity="left"
        android:layout_row="0"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:text="test"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#FFAAAAAA"
        android:textIsSelectable="false" /&gt;

    &lt;TextView
        android:id="@+id/subscriberFieldTextText"
        android:layout_column="1"
        android:layout_gravity="left"
        android:layout_row="0"
        android:paddingRight="10dp"
        android:paddingTop="5dp"
        android:text="test"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textIsSelectable="false" /&gt;
&lt;/GridLayout&gt;
</code></pre>

<p>I am adding these "rows" by code like this:</p>

<pre><code>view = LayoutInflater.from(this).inflate(R.layout.subscriber_field_text, null);

((TextView) view.findViewById(R.id.subscriberFieldTextPrefix)).setText(currentSubscriber.GetSpecialFields().get(i).GetField() + ": ");
((TextView) view.findViewById(R.id.subscriberFieldTextText)).setText(currentSubscriber.GetSpecialFields().get(i).GetValue());

registerForContextMenu(((TextView) view.findViewById(R.id.subscriberFieldTextPrefix)));
registerForContextMenu(((TextView) view.findViewById(R.id.subscriberFieldTextText)));

layout.addView(view);
</code></pre>

<p>This would be my event for creating the menu:</p>

<pre><code>@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) 
{
    menu.add(Menu.NONE, 1, 1, "test2");
}
</code></pre>

<p>Now in this event I can get the ID of the original field which only leads me to the template in the XML. And I also get the text on the original field but I have no idea how to get both of them. The text is completely enough, I don't need the objects.</p>

<p>I hope somebody can help... thank you.</p>
