こんにちはテキストビューでテキストを設定しました。SpannedStringをSpannableに変換する方法
TextView tweet = (TextView) vi.findViewById(R.id.text);
tweet.setText(Html.fromHtml(sb.toString()));
その後、私はSpannble
へTextView
のテキストを変換する必要があります。私は、これはのようにやったので:
Spannable s = (Spannable) tweet.getText();
私は関数にTextView
を渡されたので、私はそれSpannable
変換する必要があります。
private void stripUnderlines(TextView textView) {
Spannable s = (Spannable) textView.getText();
URLSpan[] spans = s.getSpans(0, s.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = s.getSpanStart(span);
int end = s.getSpanEnd(span);
s.removeSpan(span);
span = new URLSpanNoUnderline(span.getURL());
s.setSpan(span, start, end, 0);
}
textView.setText(s);
}
private class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
これは何のエラー/警告を示していません。しかし、ランタイムエラーを投げる:
java.lang.ClassCastException: android.text.SpannedString cannot be cast to android.text.Spannable
どのように私はスパンテキストにテキストビューのテキストを変換することができますか?または、関数内でSpannedStringを使用して同じタスクを実行できますか?
UIの人が下線のないリンクを作ることにしたときにひどいですか?同じことをやっている。 – portfoliobuilder