How to add bulleted list to android application?

后端 未结 17 1351
抹茶落季
抹茶落季 2020-11-29 19:14

I have googled my question but there is not working answer provided. How do add a bulleted list to my textview.

17条回答
  •  攒了一身酷
    2020-11-29 19:58

    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.

提交回复
热议问题