Code example for SpannableStringBuilder

Methods: append, charAt, length

0
		 
		if (headingBuilder.toString().trim().length() > 0) {
		 
			String heading = headingBuilder.append("\n").toString();
	 
			if (sb.length() == 0) {
					//First header 
					sb.append(heading);
				} else if (sb.charAt(0) == '\'' || sb.charAt(sb.length() - 1) == '\'') {
					//Last character is apostrophe special case sometimes it will stuff up because header is split into two 
					sb.append(heading);
				} else if (heading.equals("'")) {
					//The case by which the first section of header is apostrophe 
						sb.append(heading);
				} else if (sb.charAt(sb.length() - 1) != '\n'){
					// If not new line then start new line because it is supposed to be like H1 
					sb.append("\n ");
					sb.append(heading);
				} else { 
					sb.append(' ');
					sb.append(heading);
				} 
			int length = heading.length();
			sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), sb.length() - length, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			headingBuilder.delete(0, headingBuilder.length());
		} 
	}