I have spanableString like below
TextView contentNews = findViewById(R.id.text)
.........
.........
//article.getP() is HTML string
.........
CharSequence sequence = Html.fromHtml(article.getP(), this, null);
SpannableString spannableString = new SpannableString(sequence);
Linkify.addLinks(spannableString, Linkify.ALL);
URLSpan[] urlSpans = spannableString.getSpans(0, spannableString.length(), URLSpan.class);
for(URLSpan span : urlSpans){
Timber.d("LINK SPAN %s",span.getURL());
int start = spannableString.getSpanStart(span);
int end = spannableString.getSpanEnd(span);
int flag = spannableString.getSpanFlags(span);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick( View widget) {
Toast.makeText(NewReadingActivity.this, "Click " + span.getURL(), Toast.LENGTH_SHORT).show();
}
};
spannableString.setSpan(clickableSpan, start, end, flag);
}
contentNews.setText(spannableString);
but when I clicked it did nothing, Log Timber also managed to find the URLs like the following:
01-16 20:42:55.560 mobile.android.tribun.daerah.jambi D/NewReadingActivity:418: LINK SPAN http://TRI-TIM.COM
Finally i had an answer of my question. What i did is to change code snippet like this
Then do action click like below