How to add bulleted list to android application?

How do add a bulleted list to my textview?


Solution 1:

Tough to do as ul/li/ol are not supported. Fortunately you can use this as syntactic sugar:

&#8226; foo<br/>
&#8226; bar<br/>
&#8226; baz<br/>

&#8226; 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));

Solution 2:

  1. 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.

  2. 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.)

  3. 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.

  4. 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:

  • Bullets with correct indent after text wraps.
  • You can combine other formatted or not formatted text in one instance of TextView
  • You can define in the BulletSpan constructor how big the indent should be.

Negative:

  • You have to save every item of the list in a separate string resource. So u can not define your list that comfortable how you could in HTML.

Solution 3:

I have found an alternate.. just copy this bullet " • " (it is a text) and paste in your text view's text, you can change the bullet color by changing the textcolor and as well all other attributes like size, height width... :)

you can use short-cut to get this bullet while typing

for windows

ALT + 7

for mac

ALT + 8