I have googled my question but there is not working answer provided. How do add a bulleted list to my textview.
Went completely overkill and made a custom text view.
Use it like this:
and the code:
package com.blundell;
import android.content.Context;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.TextView;
public class BulletTextView extends TextView {
private static final String SPLITTER_CHAR = "--";
private static final String NEWLINE_CHAR = "
";
private static final String HTML_BULLETPOINT = "•";
public BulletTextView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.textViewStyle);
}
public BulletTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
checkForBulletPointSplitter();
}
private void checkForBulletPointSplitter() {
String text = (String) getText();
if (text.contains(SPLITTER_CHAR)) {
injectBulletPoints(text);
}
}
private void injectBulletPoints(String text) {
String newLinedText = addNewLinesBetweenBullets(text);
String htmlBulletText = addBulletPoints(newLinedText);
setText(Html.fromHtml(htmlBulletText));
}
private String addNewLinesBetweenBullets(String text) {
String newLinedText = text.replace(SPLITTER_CHAR, NEWLINE_CHAR + SPLITTER_CHAR);
newLinedText = newLinedText.replaceFirst(NEWLINE_CHAR, "");
return newLinedText;
}
private String addBulletPoints(String newLinedText) {
return newLinedText.replace(SPLITTER_CHAR, HTML_BULLETPOINT);
}
}