Reputation: 808
Just a quick question: Do you know why i can do that:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent + BookingSettings.getBookingSegment().substring(0, 6));
The text is not underlined.
Whereas, if i do only that:
pnrCode = (TextView)findViewById(R.id.pnr);
SpannableString pnrContent = new SpannableString("PNR: ");
pnrContent.setSpan(new UnderlineSpan(), 0, pnrContent.length(), 0);
pnrCode.setText(pnrContent);
The text is underlined.
I have to create two textview ? Do you know another solution ?
Any help is appreciated ;)
Upvotes: 2
Views: 935
Reputation: 1007554
I have to create two textview ?
No.
pnrContent + BookingSettings.getBookingSegment().substring(0, 6)
is probably going to give you a String
back, as I believe the +
operator will convert both sides to String
objects, then perform the concatenation. Hence, you will lose your formatting.
Instead, use new SpannableString("PNR: "+ BookingSettings.getBookingSegment().substring(0, 6));
, and set the length of the UnderlineSpan
as needed.
Upvotes: 7