assemble SpannableString - Android Graphics

Android examples for Graphics:Spannable

Description

assemble SpannableString

Demo Code


//package com.java2s;

import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.BulletSpan;

public class Main {
    public static CharSequence assemble(CharSequence s1, CharSequence s2) {
        SpannableString ss1 = new SpannableString(s1);
        SpannableString ss2 = checkForBullet(s2);
        return concat(ss1, ss2);
    }/*w  w  w  . j  ava2s  .  c o m*/

    public static SpannableString checkForBullet(CharSequence s) {
        SpannableString ss;
        // if the first element of the string is a '-' it means
        // it should be displayed as a bullet. we then remove the
        // '-' from the list and trim the spaces
        s = ((String) s).trim();
        if (s.length() > 0 && s.charAt(0) == '-') {
            s = ((String) s.subSequence(1, s.length())).trim();
            ss = new SpannableString(s + "\n");
            ss.setSpan(new BulletSpan(15), 0, s.length(), 0);
        } else {
            ss = new SpannableString(s + "\n");
        }
        return ss;
    }
}

Related Tutorials