C
C
Chvalov2015-10-24 16:56:21
Java
Chvalov, 2015-10-24 16:56:21

How to bold a piece of text before a specific comma in Android?

For example, there is a text written to a String variable

String a = "Вася, Петя, Степа, Тостер, Ява, Вика, ***, ***, ***";
and so, separated by commas, 80 different words, numbers, etc. are written.
And there is a variable of type int in which there is a value from 0 to 79
I display the text from the String variable in a TextView, and I give a value to a variable of type int, for example 7, after which I need to bold a piece of text that comes before the 7th comma, how to implement this?
For example:
String test = "Тостер, ВК, Пиво, Водка, Вопрос, Ответ, ****, ****"
int num = 1;

And display in the test view in this form:
Toaster, VK , Beer, Vodka, Question, Answer, ****, ****

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-10-24
@gadfi

Spannable text = new SpannableString(test);
text .setSpan(new StyleSpan(Typeface.BOLD), 7, 9, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(text);

or
textView.setText(Html.fromHtml("Тостер, <strong>ВК</strong>, Пиво, Водка, Вопрос, Ответ, ****, ****"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question