Reputation: 2821
i have a textview with large text in it, but i want to give bulletpoints, line breaks , i tried placing xml entities like •
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/>•welcome 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
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
Reputation: 1856
Try this out:
String s = "hello world"
+ System.getProperty ("line.separator")
+ "hello android"
+ System.getProperty ("line.separator");
Upvotes: 0
Reputation: 1669
Add in string.xml file
<string name="str">•item 1\n •item 2 \n • item 3</string>
Upvotes: 0
Reputation: 2821
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.
Upvotes: 7
Reputation: 1281
place this code in strings.xml
hi how are you \n
• welcome to stackoverflow
set this text to your textview
Upvotes: 5
Reputation: 72633
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));
Upvotes: 4