Home » Android » android – ListView with TextView autoLink not receiving OnItemClickListener

android – ListView with TextView autoLink not receiving OnItemClickListener

Posted by: admin June 15, 2020 Leave a comment

Questions:

My PostFragment.java implements AbsListView.OnItemClickListener, and I get the
onItemClick event without a problem on every item, unless there’s a link on the TextView: lblListItem.
The link on the TextView can be clicked without a problem and open a website, but the background of the list cannot be clicked and so the onItemClick is never called.

Example of a link string: http://www.google.com

I have this TextView on my list_item.xml:

        <TextView
        android:id="@+id/lblListItem"
        style="@style/TextView.ListItem"
        android:text="Text."
        android:layout_below="@+id/imgUser"
        android:layout_marginBottom="@dimen/margin_small"
        android:autoLink="all"
        android:linksClickable="true"
        />

I think that this is relevant, on my adapter I have some items that receive:

view.setOnClickListener()...

How can I make the list item clickable at the same time the link for the website is clickable?

How to&Answers:

Try adding android:descendantFocusability="blocksDescendants" to the root view in your row layout. I’ve done some testing with this and it seems to work.