Note that there are some explanatory texts on larger screens.

plurals
  1. POOnItemClickListener and OnClickListener in ListView
    primarykey
    data
    text
    <p>I have a custom view for each row in a custom ListAdapter and I am trying to perform onClick action and get the row position in the list where the click came from. </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="10dip" android:id="@+id/itemRoot" android:clickable="false"&gt; &lt;TextView android:layout_width="wrap_content" android:text="TextView" android:layout_height="wrap_content" android:id="@+id/itemTxt" android:layout_alignParentLeft="true" android:layout_centerVertical="true"&gt;&lt;/TextView&gt; &lt;TextView android:layout_toRightOf="@+id/itemTxt" android:text="TextView" android:layout_height="wrap_content" android:layout_alignBottom="@+id/itemTxt" android:id="@+id/amountTxt" android:paddingLeft="6dip" android:layout_centerVertical="true" android:layout_width="match_parent"&gt;&lt;/TextView&gt; &lt;ImageView android:id="@+id/delBtn" android:layout_height="wrap_content" android:src="@drawable/delete" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:paddingRight="10dip" android:layout_centerVertical="true"&gt;&lt;/ImageView&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I want to figure out when TextView or ImageView is clicked, I also need to know what row in the list it came form. I have tried using OnItemClickListener and it works fine to get the row where the click comes from. However, once I register an OnClick listener for the views, the onItemClicked() method gets skipped and onClick() is executed straight away, but there is no way of getting the row position that the view is in(or at least not that I know if).</p> <p>If I set clickable to false for the views, then onItemClicked get called and I tried manually calling performClick() on the given view. But this only works for the root element (RelativeLayout), and if click comes from TextView inside the layout the click doesn't propagate.</p> <p>I can't really figure out how to get both position in the list and perform onClick action.</p> <p>Any thoughts are welcome.</p> <p>Alex</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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