简体   繁体   中英

How to have a clickable link in a textview, within a custom listview and still have clickable listview

I have a "setOnItemClickListener" for a custom listview that I made. When the row is clicked, a method runs. That works. I am able to get a link to be clickable in the textview from within the listview by using this...

android:autoLink="web"

But then the row becomes unclickable. Any row that does not have a link in it can be clicked. The autoLink is overriding the "setOnItemClickListener" for the listview. How do I overcome this problem?

ListView with focusable elements disable the click event on the ListView itself

To overcome it..

Add :

android:descendantFocusability="blocksDescendants"

to your listview row's root layout

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical">


    <TextView
        android:id="@+id/textview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="web"
        android:focusable="false"
        android:textSize="15sp" />
</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM