第一种方法,自定义TextView,这是参考他人的资料
Textview添加了autolink后他会截获listview的item 点击事件 package com.example.testtextviewlink; import android.content.Context; import android.text.Spannable; import android.text.style.ClickableSpan; import android.util.AttributeSet; import android.view.MotionEvent; import android.widget.TextView; /** * @author Jason zhang * @TODO * @2012-11-20 */ public class TextT extends TextView { public TextT(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public TextT(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public TextT(Context context) { super(context); // TODO Auto-generated constructor stub } @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub super.onTouchEvent(event); ClickableSpan[] links = (new SpannableString(this.getText())).getSpans(getSelectionStart(), getSelectionEnd(), ClickableSpan.class); if (links.length != 0) { links[0].onClick(this); return true; }else{ return false; } } } |
第二种是在xml文件中,在ListView的item的根布局节点上,加上
android:descendantFocusability="blocksDescendants",连接是在TextView的属性中加上autoLink属性