0

Is there a way to extract a Spannable[] stuff from string resource? Basically something similar to

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="planets_array">
        <item>Welcome to <b>Mercury</b></item>
    <item>Welcome to <b>Venus</b></item>
    <item>Welcome to <b>Earth</b></item>
    <item>Welcome to <b>Mars</b></item>
    </string-array>
</resources>

Then I would extract the array into

Resources res = getResources();
Spannable[] planets = res.getStringArray(R.array.planets_array);

But right now eclipse is telling me to change Spannable[] to String[].

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • @pskink Thanks, but it didn’t work. When I do `Spannable[] stuff = (Spannable[]) res.getTextArray(R.array.stuff_array)` I get the error `java.lang.ClassCastException: java.lang.CharSequence[] cannot be cast to android.text.Spannable[]`. I may have to do something more lengthy to construct my Spannable array. – Katedral Pillon Apr 01 '14 at 19:10
  • try to cast not the whole array but particular items like stuff[0] – pskink Apr 01 '14 at 19:17
  • that didn't work either, but then I figured that I could just use `CharSequence` to capture the formatting and that I didn't need to convert to Spannable. I could not do it without your suggestion to use `getTextArray` so I would like to give the credit to you. Do you mind posting as response so I may mark this thread as resolved? thanks. – Katedral Pillon Apr 01 '14 at 19:50

1 Answers1

1

use getTextArray, it returns CharSequence[] instead of String[] which preserves attached spans

pskink
  • 23,874
  • 6
  • 66
  • 77