Reputation: 134
I am new to android, i have a textView and i am doing like this to setText(There is only one text box)
Spannable wordtoSpan = new SpannableString(message);
wordtoSpan.setSpan(new ForegroundColorSpan(Color.GREEN),0,message.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
wordtoSpan.setSpan(new UnderlineSpan(),0,message.length(),0);
tv.setText(wordtoSpan);
tv.setMovementMethod(new ScrollingMovementMethod());
// Log.v(TAG, "hi");
while(line != null) {
if(message.equals(line)) {
Log.v(TAG, "hi");
while(!("end".equals(line))) {
Log.v(TAG, "hello");
line = reader.readLine();
tv.setText(tv.getText() +" \n" + line);
}
}
line = reader.readLine();
}
The Spannable string is not getting applied. But when i remove second setText then the spannable string is applied How android handles the text view.
Upvotes: 0
Views: 118
Reputation: 6460
In setText
is checked if the provided CharSequence
is an instance of Spanned
getText() is returning a CharSequence which might be an instance of Spanned
.
But if you do + " \n" + line
it gets converted to a String, so the stuff you have in Spannable
will not be applied.
Upvotes: 2