Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I created a class like this:</p> <pre><code>import android.text.SpannableStringBuilder; import android.text.style.CharacterStyle; public class StyleableSpannableStringBuilder extends SpannableStringBuilder { public StyleableSpannableStringBuilder appendWithStyle(CharacterStyle c, CharSequence text) { super.append(text); int startPos = length() - text.length(); setSpan(c, startPos, length(), 0); return this; } public StyleableSpannableStringBuilder appendWithStyle(CharacterStyle [] c, CharSequence text) { super.append(text); int startPos = length() - text.length(); for (CharacterStyle c1 : c) setSpan(c1, startPos, length(), 0); return this; } } </code></pre> <p>This allows me to do things like this:</p> <pre><code>private void buildTickerItem(DelayedQuoteServiceObject o) { Double lastPrice = Double.parseDouble(o.getValue("LastPrice")); Double dayChange = Double.parseDouble(o.getValue("DayChange")); Double percentChange = Double.parseDouble(o.getValue("PercentDayChange")) / 100; if (o.isIndex() == true) { tickerTapeData.appendWithStyle(new StyleSpan(Typeface.BOLD),o.getDisplayName()); tickerTapeData.append(" "+ indexFormat.format(lastPrice) + " ("); if (dayChange &gt;= 0) tickerTapeData.appendWithStyle(new ForegroundColorSpan(Colours.getTickerPositive()), indexFormat.format(dayChange)); else tickerTapeData.appendWithStyle(new ForegroundColorSpan(Color.RED), indexFormat.format(dayChange)); } else { tickerTapeData.appendWithStyle(new StyleSpan(Typeface.BOLD), o.ticker); tickerTapeData.append("@"+ dollarFormat.format(lastPrice) + " ("); if (dayChange &gt;= 0) tickerTapeData.appendWithStyle(new ForegroundColorSpan(Colours.getTickerPositive()), dollarFormat.format(dayChange)); else tickerTapeData.appendWithStyle(new ForegroundColorSpan(Color.RED), dollarFormat.format(dayChange)); } tickerTapeData.append("/"); if (dayChange &gt;= 0) tickerTapeData.appendWithStyle(new ForegroundColorSpan(Colours.getTickerPositive()), percentFormat.format(percentChange)); else tickerTapeData.appendWithStyle(new ForegroundColorSpan(Color.RED), percentFormat.format(percentChange)); tickerTapeData.append(") "); } </code></pre> <p>To create a ticker tape. Works pretty nicely and keeps the code clean.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload