title: getting text of custom listview item on its click
body: <p>I have a custom layout for the <code>ListView</code> which is as follows -</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_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="@drawable/plain" &gt;
  
      &lt;TextView
          android:id="@android:id/text1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_vertical"
          android:minHeight="?android:attr/listPreferredItemHeight"
          android:paddingLeft="6dip"
          android:textSize="16sp"
          android:textColor="#000000"
          android:paddingRight="10dip"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When I click the item in a listview, I am getting error - </p>
  
  <blockquote>
    <p>02-28 17:37:38.240: E/AndroidRuntime(20869): FATAL EXCEPTION: main
    02-28 17:37:38.240: E/AndroidRuntime(20869):
    java.lang.ClassCastException: android.widget.LinearLayout cannot be
    cast to android.widget.TextView</p>
  </blockquote>
  
  <p>This is because now I am using custom listview layout as above which is wrapped in a linearlayout.</p>
  
  <p>The error line is-</p>
  
  <pre><code>class ListItemClickedonPaired implements OnItemClickListener
      {
          @SuppressLint("NewApi")
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,long id) {
  
              final String info = ((TextView) view).getText().toString(); //ERROR HERE
           }
       }
  </code></pre>
  
  <p><strong>My question is-</strong></p>
  
  <p>How to get the text of the clicked item (technically a textview) when we have these as a custom items of a listview defined with above xml ?</p>