Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bulleted list to android application?

How do add a bulleted list to my textview?

like image 805
user590849 Avatar asked Feb 14 '11 13:02

user590849


People also ask

How do I insert bullet points in Android?

The two Button s at the bottom have android:text="◄" and "►" .

How do I add bullet points in XML?

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

How do I add bullets to my website?

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


2 Answers

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)); 
like image 151
browep Avatar answered Oct 07 '22 03:10

browep


  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.
like image 20
Diego Frehner Avatar answered Oct 07 '22 03:10

Diego Frehner