Home » Android » java – Android: how to give bulletpoints, line break to text in textview

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

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&Answers:

Thank you all…i finally ended up doing this

String nodata="hi how are you<br/>•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.

Answer:

You forgot the colon after

So change it to this:

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

Answer:

place this code in strings.xml

hi how are you \n

•  welcome to stackoverflow

set this text to your textview

Answer:

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

Answer:

Add in string.xml file

<string name="str">•item 1\n •item 2 \n • item 3</string>

Answer:

Try this out:

String s = "hello world"
           + System.getProperty ("line.separator")
           + "hello android"
           + System.getProperty ("line.separator");