ClassCastException when getting the selected item of ListView as string or textview
<p>I got <strong>runtime error</strong> exception:     </p>

<pre><code>java.lang.ClassCastException: android.widget.TwoLineListItem cannot be cast to android.widget.TextView
</code></pre>

<p>My Activity extends Activity <strong>NOT</strong> ListActivity and here is my layout construction:</p>

<pre><code>&lt;LinearLayout ...&gt; &lt;ListView ...&gt;&lt;/ListView&gt; &lt;/LinearLayout&gt;
</code></pre>

<p><strong>Java:</strong></p>

<pre><code>   ListView lv1 = (ListView) findViewById(R.id.listViewXMLdata);
    ArrayAdapter&lt;String&gt; arrAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_2,
        android.R.id.text2, getResources().getStringArray(R.array.countries));

    lv1.setAdapter(arrAdapter);

    lv1.setOnItemClickListener(new OnItemClickListener() {          
        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {              
            lView.getItemAtPosition(position);

            String itemSelected = ((TextView) view).getText().toString();
            Toast.makeText(getApplicationContext(), "Clicked Position Number " + position + ": " + itemSelected ,
                    Toast.LENGTH_SHORT)
                    .show();


        }
    });
</code></pre>

<p>My only main concern is just to get the string (item selected) on my list.</p>

<p><strong>NOTE 1</strong>: I am not working on any database.</p>

<p><strong>NOTE 2</strong>: I already tried casting it to CharSequence itemSelected =  ((TextView) view).getText().toString()  but still got runtime error.</p>

<p>The runtime error occurs only when I started to select item on the list.</p>
