How do add a bulleted list to my textview?
The two Button s at the bottom have android:text="◄" and "►" .
A lists is defined by adding a list element to the documentation XML. This element must include a "type" attribute, which determines how the final rendered list will be displayed. For a bulleted list, the attribute's value should be set to "bullet".
</ul> tags around the text to turn into a bulleted list. Second, place the <li>… </li> tags around each line item in the list. You can choose from three formatting type choices when making HTML bullet points.
Tough to do as ul/li/ol are not supported. Fortunately you can use this as syntactic sugar:
• foo<br/> • bar<br/> • baz<br/>
•
is the html entity for a list bullet more choices are here http://www.elizabethcastro.com/html/extras/entities.html
more about which tags are supported provided by Mark Murphy (@CommonsWare) http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html Load that up with Html.fromHtml
((TextView)findViewById(R.id.my_text_view)).setText(Html.fromHtml(myHtmlString));
browep explained nice the way over HTML. The provided solution with the html entity can be useful. But it includes only the bullet. If your text wraps, the indent will not be correct.
I found other solutions embedding a web view. That maybe is appropriate for some, but i think its kind of overkill... (The same with using a list view.)
I like the creative approach of Nelson :D, but it does not give you the possibility of adding an unordered list to a text view.
My example of an unordered list with bullets using BulletSpan
CharSequence t1 = getText(R.string.xxx1); SpannableString s1 = new SpannableString(t1); s1.setSpan(new BulletSpan(15), 0, t1.length(), 0); CharSequence t2 = getText(R.string.xxx2); SpannableString s2 = new SpannableString(t2); s2.setSpan(new BulletSpan(15), 0, t2.length(), 0); textView.setText(TextUtils.concat(s1, s2));
Positive:
Negative:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With