【问题标题】:How to have a clickable link in a textview, within a custom listview and still have clickable listview如何在自定义列表视图中的文本视图中具有可点击的链接并且仍然具有可点击的列表视图
【发布时间】:2017-04-25 19:34:54
【问题描述】:

我有一个“setOnItemClickListener”用于我制作的自定义列表视图。单击该行时,将运行一个方法。这样可行。我可以通过使用此链接从列表视图中获取可在文本视图中单击的链接...

android:autoLink="web"

但随后该行变得不可点击。任何没有链接的行都可以被点击。自动链接覆盖列表视图的“setOnItemClickListener”。我该如何克服这个问题?

【问题讨论】:

    标签: android listview onitemclicklistener clickable


    【解决方案1】:

    ListView 带有可聚焦元素会禁用 ListView 本身的点击事件

    克服它..

    添加:

    android:descendantFocusability="blocksDescendants"
    

    到您的列表视图行的根布局

     <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>
    

    【讨论】:

    • 如果其中有链接,这不会使该行可点击。
    • 那行得通。我误解了你的意思。感谢您的编辑和澄清。
    猜你喜欢
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    相关资源
    最近更新 更多