Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TableView as itemview in ListView not clickable
    text
    copied!<p>I am using a custom adapter with a ListView and using a custom layout to supply the list itemviews. My layout is like this</p> <pre><code>&gt; LinearLayout &gt; TableView &gt; TableRow &gt; TextView &gt; TextView </code></pre> <p>This results in list items that do not respond to clicks but if I edit the layout to the following it works</p> <pre><code>&gt; LinearLayout &gt; TextView &gt; TextView </code></pre> <p>So I know that there is nothing wrong with my Adapter and Activity.</p> <p>I have tried adding <code>android:descendantFocusability="blocksDescendants"</code> to the top level linear layout as suggested in this question <a href="https://stackoverflow.com/questions/2985890/listview-items-not-clickable-with-horizontalscrollview-inside">ListView items not clickable with HorizontalScrollView inside</a></p> <p>I have also tried adding <code>android:clickable="true"</code> and <code>android:focusable="true"</code> to the <code>TableView</code> but this does not work either.</p> <p>Any ideas?</p> <hr> <p>EDIT </p> <p>layout XML source code</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="fill_parent" android:layout_height="wrap_content"&gt; &lt;TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="1" &gt; &lt;TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:paddingTop="10dp" android:paddingBottom="10dp" android:gravity="center_vertical"&gt; &lt;TextView android:id="@+id/ITEMVIEW_TEXT2_lblText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:paddingRight="5dp" android:paddingLeft="15dp" /&gt; &lt;TextView android:id="@+id/ITEMVIEW_TEXT2_lblText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textColor="#ff385487" android:gravity="right" android:paddingRight="15dp" /&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/LinearLayout&gt; </code></pre> <hr> <p>EDIT</p> <p>I have tried adding <code>android:focusable="false"</code> as suggested <a href="https://stackoverflow.com/questions/1121192/android-custom-listview-unable-to-click-on-items">here</a> and <a href="https://stackoverflow.com/questions/3611551/textview-and-button-in-each-row-and-onlistitemclick">here</a> but that does not work either.</p> <hr> <p>EDIT</p> <p>All I really wanted to achieve here was laying out two columns of text one aligned left and the other right. I figured out a better layout to achieve this that does not use TableView so my ListView items remain clickable, it also uses less views so it will also be more efficient, this is it</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="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/ITEMVIEW_TEXT2_lblText" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:textSize="20sp" android:paddingRight="5dp" android:paddingLeft="15dp" /&gt; &lt;TextView android:id="@+id/ITEMVIEW_TEXT2_lblText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20sp" android:textColor="#ff385487" android:gravity="right" android:paddingRight="15dp" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>This is not a solution to the problem of TableView making ListView items non clickable but I have noted it here in case anyone else is looking to figure out how to do a similar layout.</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