I'm trying to add bullets to the unordered lists using BulletSpan. But, I cannot find bullets in the list. Below is my code:
private static String appendBullet(int leadingMargin, String liText) {
SpannableString spannableString = new SpannableString(liText);
spannableString.setSpan(new BulletSpan(leadingMargin), 0, liText.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
Log.d("Ul tags", String.valueOf(spannableString));
return spannableString.toString();
}
Here liItext is the list item. I'm adding a BulletSpan here and then returning the item and adding it to the list and finally adding the entire list to the StringBuilder.
liList.add(appendBullet(15, liText));
List<String> liList = addListWithBullets(lists, new ArrayList<String>());
if (liList.size() > 0) {
for (String str : liList) {
builder.append(str);
builder.append("<br/>");
}
Log.d("Ul tags", String.valueOf(liList));
}
First of all you probably want to use
SpannableStringBuilderinstead ofStringBuilder. Secondly, in yourappendBullet(...)method by callingtoString()on theSpannableStringinstance you're probably losing all of the spanning information! What you probably want to do instead is append eachStringwhich is to be bulleted to theSpannableStringBuilderinstance and then call thesetSpan(...)method on theSpannableStringBuilderinstance for each of theseStrings.If it helps I've put together an extension function on the
SpannableStringBuilderclass which takes away some of this difficulty for you. You can find here.