Android:如何使Linkify链接不长
我有一些使用Linkify的TextView。 我希望链接不要长时间点击。 在TextView上使用setLongClickable(false)对Linkify链接没有任何影响。 有没有办法让这些链接不能长时间点击?
这会对你有所帮助
Spannable span = Spannable.Factory.getInstance().newSpannable("my span text");
Linkify.addLinks(span, Linkify.ALL);
URLSpan[] uspans = span.getSpans(0, mTextAdData.length(), URLSpan.class);
int i = 0;
for (URLSpan uspan : uspans) {
int start = span.getSpanStart(uspan);
int end = span.getSpanEnd(uspan);
span.removeSpan(uspan);
MyUrlSpan uspan1 = new MyUrlSpan(uspan.getURL());
span.setSpan(uspan1, start, end, 0);
if (i != start) {
// From i to start of this span set a custom span
span.setSpan(new MyUrlSpan(), i, start,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
i = end;
}
public class MyUrlSpan extends URLSpan implements OnLongClickListener {
public MyUrlSpan(String string) {
super(string);
}
@Override
public void onClick(View v){
}
@Override
public boolean onLongClick(View v) {
return false;
}
}
原来,解决办法很简单:
textview.setOnLongClickListener(new OnLongClickListener(){
public boolean onLongClick(View v) {
return true;
}
});
尝试这个...
Link.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
Link.setLongClickable(false);
return false;
}
});
Link.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (!Link.isLongClickable()) {
Link.setLongClickable(true);
return;
}
// Link your page
}
});
链接地址: http://www.djcxy.com/p/12953.html