How to read a color using R.color by using a variable ID
<p>I have the following colors defined in color.xml. The color names are BC1, BC2, BC2 etc. There are 15 such color names defined. The last color is BC15.</p>

<pre><code>&lt;color name="BC1"&gt;#39DD02&lt;/color&gt;
&lt;color name="BC2"&gt;#FEA200&lt;/color&gt;
&lt;color name="BC3"&gt;#21C3F3&lt;/color&gt;
........
&lt;color name="BC15"&gt;#21F3F3&lt;/color&gt;
</code></pre>

<p>In my code I am trying to get the color with the following code:</p>

<pre><code>ContextCompat.getColor(getContext(), R.color.BC1)
</code></pre>

<p>The above code works fine. Now, I want to use this code inside a loop so that I can pick the color based on a counter value, so that I can read colors one by one, as in the following psedo-code.</p>

<pre><code>for(colorID=1;colorID&lt;=15;colorID++)
{

     int businessColor=ContextCompat.getColor(getContext(),R.color.&lt;colorID&gt; )

     //Do something with the value inside businessColor 
}
</code></pre>

<p>In the above code, how do I use the colorID counter to read colors one by one</p>

<p>I tried to write the following. (Assuming that I can get hexdecimal value from an array)</p>

<pre><code>ContextCompat.getColor(getContext(), Color.parseColor("#636161"))
</code></pre>

<p>But the above code shows me error "<strong>Expected resource of type color</strong>".</p>