在 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();
}
});
最佳答案
如果列表的任何行项目包含 Focusable
或 Clickable
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/