Linkify with TextView
I want to use Linkify with my extended TextView, but if i use Linkify in overrided setText() method fails because of endless cycle.
I found such solution, but it isn't pretty:
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(bypass){
bypass = false;
return;
}
bypass = true;
if(!Linkify.addLinks(textView, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES)){
Linkify.addLinks(textView, phoneMatcher, "tel:", null, Linkify.sPhoneNumberTransformFilter);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Is there a way to use Linkify on TextView without such workaround? I want that my extended TextView automatically add links if there is any.
Found a proper solution, to use
addLinks(Spannable s, Pattern p, String scheme, MatchFilter matchFilter, TransformFilter transformFilter)
and then set spannable using
setText(Spannable spannable)
method.
链接地址: http://www.djcxy.com/p/74634.html上一篇: 在TextView中从Android中链接HTML
下一篇: Linkify与TextView