android - 使 Web 链接在 TextView (ListItem 的)中可点击

标签 android

ListView Adapter 的 getView() 函数中我有这个:

holder.comment.setText(Html.fromHtml(comment));
holder.comment.setMovementMethod(LinkMovementMethod.getInstance());

holder.comment 是一个 TextView

在包含此 ListView 的 Activity 中,我实现了 onItemClick Listener。在我启用之前一直有效

holder.comment.setMovementMethod(LinkMovementMethod.getInstance());

现在项目点击监听器不工作了,好像这行代码覆盖了点击行为。单击事件仅适用于在浏览器中打开链接的 TextView (holder.comment)。单击 ListView 项的任何其他部分都不起作用。

编辑:

commentsListView
    .setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            Toast.makeText(CommentsActivity.this,"" + arg2,Toast.LENGTH_LONG).show();
        }
    });

最佳答案

如果列表的任何行项目包含 FocusableClickable View ,则 OnItemClickListener 将不起作用。

行项目必须有类似的参数

android:descendantFocusability="blocksDescendants"

你的list_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >

// your other TextView and Other widget here

</LinearLayout>

关于android - 使 Web 链接在 TextView (ListItem 的)中可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852649/

相关文章:

Android:如何对 "IllegalStateException: Can not perform this action after onSaveInstanceState"进行单元测试

android - 检测用户在 OpenGL 正方形上的触摸

java - : "Events are received on the UI thread and read on the main loop thread"?是什么意思

Android Recycler并排查看项目

java - 增强现实 - 图像大小变换

android - 使用 Android Service Backup (Cloud Backup) 时出现 Unclear SecurityException

安卓谷歌浏览器 : CSS3 Responsive Layout Bug

Android:如何使用名称从资源中获取字符串?

android - 使用 Achartengine 动态更新图表

java - 如何获取当前的 GPS 位置?