I would like to know how can I define different colors in a single textview depending on the textview repeats, for example:
If I declare something like: Color[] colors = {Color.green, Color.blue, Color.red, Color.brown, Color.yellow};
Then I want to pass "colors" somehow in tv.setBackgroundColor(Color.GREEN); instead of "Color.green" in order that if the textview repeats five times I could see the textview in green, blue, red, brown and yellow and if it's 7 times I could get green, blue, red, brown, yellow, green and blue.
Here's some code, plus an image
adapter = new SimpleCursorAdapter(this, R.layout.hrprocess_item_list, cursor, from, to, 0);
adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view.getId() == R.id.category) {
String s=cursor.getString(cursor.getColumnIndex(manager.CONTENT_CATEGORY));
TextView tv = (TextView)view;
int[] androidColors = getResources().getIntArray(R.array.androidcolors);
for (int i = 0; i < androidColors.length; i++) {
tv.setBackgroundColor(androidColors[i]);
}
tv.setText(s);
return true;
}
return false;
}
});
lv.setAdapter(adapter);
Colors.xml
<item name="azul1" type="color">#4178BE</item>
<item name="verde1" type="color">#008571</item>
<item name="morado1" type="color">#9855D4</item>
<item name="rojo1" type="color">#E71D32</item>
<item name="rojo_naranja1" type="color">#D74108</item>
<item name="amarillo1" type="color">#EFC100</item>
<item name="gris1" type="color">#6D7777</item>
<integer-array name="androidcolors">
<item>@color/azul1</item>
<item>@color/verde1</item>
<item>@color/morado1</item>
<item>@color/rojo1</item>
<item>@color/rojo_naranja1</item>
<item>@color/amarillo1</item>
<item>@color/gris1</item>
</integer-array>