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
SpannableStringBuilder
instead ofStringBuilder
. Secondly, in yourappendBullet(...)
method by callingtoString()
on theSpannableString
instance you're probably losing all of the spanning information! What you probably want to do instead is append eachString
which is to be bulleted to theSpannableStringBuilder
instance and then call thesetSpan(...)
method on theSpannableStringBuilder
instance for each of theseString
s.If it helps I've put together an extension function on the
SpannableStringBuilder
class which takes away some of this difficulty for you. You can find here.