使文本视图(ListItem)中的Web链接可单击

时间:2013-11-08 06:07:07

标签: android

ListView Adapter's getView()函数中我有:

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

holder.commentTextView

在包含此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();
        }
    });

2 个答案:

答案 0 :(得分:4)

如果列表的任何行项包含FocusableClickable视图,则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>

答案 1 :(得分:2)

因为行xml的内容阻止了listview的click事件,所以简单地将descendantFocusability属性添加到main layout of row xml.

  

机器人:descendantFocusability = “blocksDescendants”

相关问题