Get the name of an item inside an array in strings.xml

0

I have the following array:

<array name="Codes">
        <item name="Vermelho">e74c3c</item>
        <item name="Azul">3498db</item>
        <item name="Rosa">FC14E5</item>
        <item name="Roxo">8e44ad</item>
        <item name="Amarelo">f1c40f</item>
        <item name="Laranja">d35400</item>
        <item name="Verde">2ecc71</item>
        <item name="Cinza">95a5a6</item>
    </array>

I have a variable that holds the color code

Collections.shuffle(Arrays.asList(codes));
this.colorCode = "#" + codes[0];

How could I get the name=""?

    
asked by anonymous 01.03.2016 / 23:13

1 answer

1

Hello, One solution to your problem would be to create another array that has the color names in their values. As in Example

<array name="Codes">
        <item name="Vermelho">e74c3c</item>
        <item name="Azul">3498db</item>
        <item name="Rosa">FC14E5</item>
        <item name="Roxo">8e44ad</item>
        <item name="Amarelo">f1c40f</item>
        <item name="Laranja">d35400</item>
        <item name="Verde">2ecc71</item>
        <item name="Cinza">95a5a6</item>
    </array>
<array name="Colors">
            <item name="Vermelho">Vermelho</item>
            <item name="Azul">Azul</item>
            <item name="Rosa">Rosa</item>
            <item name="Roxo">Roxo</item>
            <item name="Amarelo">Amarelo</item>
            <item name="Laranja">Laranja</item>
            <item name="Verde">Verde"</item>
            <item name="Cinza">Cinza</item>
        </array>

This way you can get the name just by using the same index.

    
02.03.2016 / 21:33