Note that there are some explanatory texts on larger screens.

plurals
  1. POListview OnItemClickListener() for custom layout
    text
    copied!<p>I have my listview with custom layout</p> <p>custom_layout.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="1" &gt; &lt;TableRow&gt; &lt;TextView android:id="@+id/item1" android:layout_width="0dip" android:layout_height="wrap_content" android:padding="10dip" android:textColor="@color/white_color" android:layout_margin="4dip" android:layout_weight="0.15" /&gt; &lt;TextView android:id="@+id/item2" android:layout_width="0dip" android:layout_height="wrap_content" android:padding="10dip" android:textColor="@color/white_color" android:layout_margin="4dip" android:layout_weight="0.53" /&gt; &lt;TextView android:id="@+id/item3" android:layout_width="0dip" android:layout_height="match_parent" android:layout_gravity="right" android:gravity="right" android:padding="10dip" android:textColor="@color/white_color" android:layout_margin="4dip" android:layout_weight="0.32" /&gt; &lt;/TableRow&gt; </code></pre> <p></p> <p>Listview with arrayadapter:</p> <pre><code>ListView lv = (ListView) findViewById(R.id.prodlist); String[] from = new String[] { "rowid", "col_1", "col_2" }; int[] to = new int[] { R.id.item1, R.id.item2, R.id.item3 }; // prepare the list of all records ArrayList&lt;HashMap&lt;String, String&gt;&gt; fillMaps = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); for (int i = 0; i &lt; 20; i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put("rowid", "" + i); map.put("col_1", name); map.put("col_2", qnt); } fillMaps.add(map); SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.custom_layout, from, to); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { //How to get item2 text value?.. } }); </code></pre> <p>All three textview are added in the arrayadapter.All I want to do is when I click the listview,how to get the text of textview(r.id.item2).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload