How to add bulleted list to android application? https://stackoverflow.com/questions/4992794/how-to-add-bulleted-list-to-android-application
一、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:
- 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.
android textview 自动换行 整齐排版 https://blog.csdn.net/guankai1990/article/details/71647324
在Android中实现无序列表并非直接支持ul/li/ol标签,但可以通过使用HTML实体或其他方法来实现。例如,可以使用HTML实体`•`作为列表符号。`Html.fromHtml()`方法可以帮助加载支持的HTML标签。另外,`BulletSpan`类可以提供正确的缩进,允许在同一个TextView中混合其他格式或非格式化的文本。不过,这种方法需要将列表项分别保存为字符串资源,可能不如HTML那样灵活。
1149

被折叠的 条评论
为什么被折叠?



