title: Accessing child views inside a ListItem defined as LinearLayout
body: <p>I'm trying to retrieve the getText() value of a TextView defined in my ListItem Layout, inside the setOnItemClickListener method.</p>
  
  <p>Basically, I want to log data (Id, LookupKey, DisplayName, or PhoneNumber) allowing me to retrieve the contact selected regardless of the listview/adapter used.</p>
  
  <p>I display a simple TextView and an Imageview which visibility is set according to the data.
  here is the layout : contact_entry.xml :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content" android:baselineAligned="false"
  android:layout_width="fill_parent" android:padding="5px"&gt;
              &lt;TextView android:layout_width="wrap_content"
                  android:layout_height="wrap_content" android:textSize="16px"
                  android:text="@+id/contactEntryText" android:id="@+id/contactEntryText"&gt;
              &lt;/TextView&gt;
              &lt;TableRow android:paddingLeft="5px" android:visibility="visible"
                  android:paddingRight="5px" android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:id="@+id/indicator_logo_table"
                  android:gravity="right"&gt;
                  &lt;ImageView android:layout_width="wrap_content"
                      android:id="@+id/imageView1"
                      android:layout_height="fill_parent"
                      android:src="@drawable/indicator"&gt;
                  &lt;/ImageView&gt;
              &lt;/TableRow&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>the adapter i use is defined below :</p>
  
  <pre><code>SimpleAdapterWithImageView adapter = new SimpleAdapterWithImageView(
              this, R.layout.contact_entry, cursor, fields,
              new int[] { R.id.contactEntryText });
      mContactList.setAdapter(adapter);
  </code></pre>
  
  <p>( You could have guessed it's for displaying the contact's Display_Name from the ContactsContract ContentProvider. )</p>
  
  <p>and here is finally the mContactList.setOnItemClickListener ...</p>
  
  <pre><code>mContactList.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
              int position, long id) {
  
  LinearLayout linear = (LinearLayout) view.findViewById(R.layout.contact_entry);
  Log.i("done","linear layout"); // it's not done at all ! findViewById returns null;
  
  //this part is currently useless
  TextView displayed_name = (TextView) linear.findViewById(R.id.contactEntryText);
  Log.i("done","Displayed name = linear.findViewById contactentrytext");
  
  
   Toast.makeText(getApplicationContext(),
               // displayed_name.getText(), //
               //view.getContentDescription(), //
               Toast.LENGTH_SHORT).show();
      }       
  </code></pre>
  
  <p>As you can see i'm only trying to display a toast for the moment, in the end the name will be put as an extra for an intent. </p>
  
  <p>So : the best result i got these last 36 hours (sigh) is displaying the name of the first contact displayed in the toast, even when clicking on the second item...</p>
  
  <pre><code>TextView displayed_name = (TextView) findViewById(R.id.contactEntryText);
  Toast.makeText(getApplicationContext(),displayed_name.getText(),
                            Toast.LENGTH_SHORT).show();
                      }
  </code></pre>
  
  <p>I've been trying stuff like the tutorial google provided <a href="http://developer.android.com/resources/tutorials/views/hello-listview.html" rel="nofollow">here</a>, which (am I wrong? I'm new to Android so don't hesitate to slap me in the face ...) actually casts the whole View in a TextView ...</p>
  
  <p>plus other tricks like view.getChildAt() and so on... for hours.</p>
  
  <p>I'm convinced it's not that hard, yet i'm running in circles !
  I don't think it is because of my adapter, but if anyone thinks it could be the cause, i could provide the code in another post.</p>
  
  <p>Thanks in advance !</p>