teekib
teekib

Reputation: 2821

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

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?

Upvotes: 8

Views: 18471

Answers (6)

Inzimam Tariq IT
Inzimam Tariq IT

Reputation: 6758

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

If you want to do it via xml paste the below text in strings.xml and call this string in xml file

hi how are you \n
•  welcome to stackoverflow

In strings.xml it would look something like this

<string name="welcom_msg">hi how are you \n
•  welcome to stackoverflow</string>

Upvotes: 9

Nipun Gogia
Nipun Gogia

Reputation: 1856

Try this out:

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

Upvotes: 0

chaitanya dalvi
chaitanya dalvi

Reputation: 1669

Add in string.xml file <string name="str">&#8226;item 1\n &#8226;item 2 \n &#8226; item 3</string>

Upvotes: 0

teekib
teekib

Reputation: 2821

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.

Upvotes: 7

User
User

Reputation: 1281

place this code in strings.xml

hi how are you \n

•  welcome to stackoverflow

set this text to your textview

Upvotes: 5

Ahmad
Ahmad

Reputation: 72633

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)); 

Upvotes: 4

Related Questions