2

I have a textView with text let's say

• I am asking a question from
stackoverflow

How can I make my textView show it like

• I am asking a question from
  stackoverflow




String facil = accomodation.facilities;
facil = facil.replace("<>", "%");
Spanned sp = Html.fromHtml(facil);
facil = sp.toString();

String[] items = facil.split("%");
CharSequence allFacil = "";

for (int i = 0; i < items.length; i++)
{
    String text = items[i];
    SpannableString s = new SpannableString("• " + text + "\n");
    s.setSpan(new BulletSpan(BulletSpan.STANDARD_GAP_WIDTH), 0, text.length(), 0);          
    allFacil = TextUtils.concat(allFacil, s);         
} 

facilities.setText(allFacil.toString());
Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193
  • you could have a look at this http://stackoverflow.com/questions/14190477/how-to-indent-text-in-a-textview-in-android or this http://stackoverflow.com/questions/7153777/ordered-list-in-xml-in-android – Rachel Gallen May 08 '13 at 14:27
  • Would these bullet point strings be dynamic, or would you be grabbing them from your strings resource? – Tom May 08 '13 at 14:27
  • Try [this answer](http://stackoverflow.com/questions/4992794/how-to-add-bulleted-list-to-android-application) out. – Tom May 08 '13 at 14:30
  • Tom. I am getting simple strings from internet... Replacing <> with \nbullets and then showing then in a textView. If there is any way even by increasing the number of textviews i will adopt – Muhammad Umar May 08 '13 at 14:30

1 Answers1

4

I have done it like this...

String[] items = new String[] { "item 1", "item 2", "item 3" };
CharSequence allText = "";
for (int i = 0; i < items.length; i++)
{
    String text = items[i];
    SpannableString s = new SpannableString(text + "\n");
    s.setSpan(new BulletSpan(BulletSpan.STANDARD_GAP_WIDTH), 0, text.length(), 0);          
    allText = TextUtils.concat(allText, s);         
} 

...

public class BulletSpan implements LeadingMarginSpan...
WindRider
  • 11,958
  • 6
  • 50
  • 57
  • please check my edited code. I have tried but nothing happens. I have to do some fixing to my retrieved string since its HTML Based – Muhammad Umar May 08 '13 at 15:51
  • 1
    cool it worked. i was adding toString to char sequence, it was removing bullets. Worked with this line s.setSpan(new BulletSpan(), 1, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); – Muhammad Umar May 08 '13 at 17:38