I have googled my question but there is not working answer provided. How do add a bulleted list to my textview.
I find this to be the easiest way, leave the textView as it is in the xml file and use the following java code. it worked perfectly fine for me.
private static final String BULLET_SYMBOL = "•";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tutorial);
TextView tv = (TextView) findViewById(R.id.yourTextView);
tv.setText("To perform this exercise you will need the following: "
+ System.getProperty("line.separator")//this takes you to the next Line
+ System.getProperty("line.separator")
+ Html.fromHtml(BULLET_SYMBOL + " Bed")
+ System.getProperty("line.separator")
+ Html.fromHtml(BULLET_SYMBOL + " Pillow"));
}
another way to support the missing HTML tags, is by replacing them nicely, as shown here
Tough to do as ul/li/ol are not supported. Fortunately you can use this as syntactic sugar:
• foo<br/>
• bar<br/>
• baz<br/>
•
is the html entity for a list bullet
more choices are here http://www.elizabethcastro.com/html/extras/entities.html
more about which tags are supported provided by Mark Murphy (@CommonsWare) http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html Load that up with Html.fromHtml
((TextView)findViewById(R.id.my_text_view)).setText(Html.fromHtml(myHtmlString));
Inspired by the various answers here, I created a Utility class to make this an easy one liner. This will create a bulleted list with indentation for wrapped text. It has methods for combining strings, string resources and string array resources.
It will create a CharSequence which you can pass to a TextView. For example:
CharSequence bulletedList = BulletListUtil.makeBulletList("First line", "Second line", "Really long third line that will wrap and indent properly.");
textView.setText(bulletedList);
Hope it's helpful. Enjoy.
Note: This will use the system standard bullet, a small circle the same color as the text. If you want a custom bullet, consider subclassing BulletSpan and overriding its drawLeadingMargin()
to draw the bullet you want. Take a look at the BulletSpan source for an idea how it works.
public class BulletTextUtil {
/**
* Returns a CharSequence containing a bulleted and properly indented list.
*
* @param leadingMargin In pixels, the space between the left edge of the bullet and the left edge of the text.
* @param context
* @param stringArrayResId A resource id pointing to a string array. Each string will be a separate line/bullet-point.
* @return
*/
public static CharSequence makeBulletListFromStringArrayResource(int leadingMargin, Context context, int stringArrayResId) {
return makeBulletList(leadingMargin, context.getResources().getStringArray(stringArrayResId));
}
/**
* Returns a CharSequence containing a bulleted and properly indented list.
*
* @param leadingMargin In pixels, the space between the left edge of the bullet and the left edge of the text.
* @param context
* @param linesResIds An array of string resource ids. Each string will be a separate line/bullet-point.
* @return
*/
public static CharSequence makeBulletListFromStringResources(int leadingMargin, Context context, int... linesResIds) {
int len = linesResIds.length;
CharSequence[] cslines = new CharSequence[len];
for (int i = 0; i < len; i++) {
cslines[i] = context.getString(linesResIds[i]);
}
return makeBulletList(leadingMargin, cslines);
}
/**
* Returns a CharSequence containing a bulleted and properly indented list.
*
* @param leadingMargin In pixels, the space between the left edge of the bullet and the left edge of the text.
* @param lines An array of CharSequences. Each CharSequences will be a separate line/bullet-point.
* @return
*/
public static CharSequence makeBulletList(int leadingMargin, CharSequence... lines) {
SpannableStringBuilder sb = new SpannableStringBuilder();
for (int i = 0; i < lines.length; i++) {
CharSequence line = lines[i] + (i < lines.length-1 ? "\n" : "");
Spannable spannable = new SpannableString(line);
spannable.setSpan(new BulletSpan(leadingMargin), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
sb.append(spannable);
}
return sb;
}
}
This is by far the easiest..
<string name="bullet_ed_list">\n\u2022 He has been Chairman of CFL Manufacturers Committee of ELCOMA, the All India Association of Lighting Equipment Manufacturers.
\n\u2022 He has been the President of Federation of Industries of India (FII).</string>
I have found an alternate.. just copy this bullet " • " (it is a text) and paste in your text view's text, you can change the bullet color by changing the textcolor and as well all other attributes like size, height width... :)
you can use short-cut to get this bullet while typing
for windows
ALT + 7
for mac
ALT + 8