Android: how to give bulletpoints, line break to text in textview

15,249

Solution 1

Thank you all...i finally ended up doing this

String nodata="hi how are you<br/>&#8226;welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound)); 

and for justify left i did change in my layout file android:layout_gravity=center|left

i hope there is a betterway doing this.

Solution 2

place this code in strings.xml

hi how are you \n

•  welcome to stackoverflow

set this text to your textview

Solution 3

If you wanna do it in java (I means dynamically) use \n for line break and Unicode character for bullet i.e. \u25CF.

This is How I'm using it

textView.setText("Welcome Username\n\u25CF Some Instructions");

It looks as
Welcome Username
● Some Instructions

Your case should be something like

textView.setText("hi how are you\n\u25CF welcome to stackoverflow");

Here are some code

• = \u2022
● = \u25CF
○ = \u25CB
▪ = \u25AA
■ = \u25A0
□ = \u25A1
► = \u25BA

Solution 4

You forgot the colon after &#8226;

So change it to this:

String nodata="hi how are you<br/>&#8226;welcome to stackoverflow"
TextView nodata= ((TextView) findViewById(R.id.nodata));
nodata.setText(Html.fromHtml(nodatafound)); 
Share:
15,249
teekib
Author by

teekib

Updated on June 30, 2022

Comments

  • teekib
    teekib almost 2 years

    i have a textview with large text in it, but i want to give bulletpoints, line breaks , i tried placing xml entities like &#8226 for bullet point in my string.xml, but unable to get linebreak and few text comes in the middle, i like to use justify too

    String nodata="hi how are you<br/>&#8226welcome to stackoverflow"  
    TextView nodata= ((TextView) findViewById(R.id.nodata));
    nodata.setText(Html.fromHtml(nodatafound));    
    

    it kind of works but I am unable to use justify , is there any way I can achieve this?

  • teekib
    teekib over 11 years
    i am sorry ..actually the question is without this quote marks ""..i edited
  • User
    User over 11 years
    <string name="text">hi how are you \n •&#160; welcome to stackoverflow \n </string> and set text to your textview in your xml file android:text="@string/text"
  • teekib
    teekib over 11 years
    what is this "&#160;" entity for ? some text is cooming in the middle how to justify to rightside?