android - How to change some words of a string to BOLD? -
this string getting web using json api in code:
string content = "<strong><em>india world’s hub child sex trafficking</em> </strong></p>\n<p style=\"text-align: center;\"><strong><em>nearly 40,000 children abducted every year… </em></strong></p>\n<p style=\"text-align: center;\"><strong<em> every8 minutes girl child goes missing in india!</em></strong></p>\n<p><strong>priti pathak</strong></p>\n<p>meet shivani shivaji roy, senior inspector, crime branch, mumbai police, sets out confront mastermind behind child trafficking mafia,"
in string whatever text in
"<strong><em> text </em></strong>"
i want display bold. above string
<strong><em>india world’s hub child sex trafficking</em></strong>
will displayed india world’s hub child sex trafficking . should happen entire string. code using:
int startindex = content.indexof("<strong><em>")+13; // 13 because <strong><em> has 13 characters string substring = content.substring(startindex, startindex+200); int subendindex = substring.indexof("</em></strong>"); int endindex = startindex + subendindex; spannablestring s = new spannablestring(content); s.setspan(new stylespan(android.graphics.typeface.bold), startindex, endindex, 0); textview.settext(s, buffertype.spannable );
this code working setting bold text text whichever first within strong tag , not rest. because setting bold text first tag.
how should startindex, endindex of "strong tags" , can set
s.setspan(new stylespan(android.graphics.typeface.bold), startindex, endindex, 0);
to texts , number of times have set span.
i though of using regex dont know how indexes using it. nice. thankyou !
Comments
Post a Comment