Question

I have int CYAN in Color class and get requested color from database

valueColor = this.getArguments().getString("valueColor", valueColor);

that is String "CYAN". How do I use this string as integer variable name in the following example?

int[] color = {color.CYAN,Color.WHITE};
Était-ce utile?

La solution

You can parse the color string, thus:

colourString = getArguments().getString("valueColor", colourString);
int valueColor = Color.parseColor(colourString);

You may need to .toLower() as the docs only lists lower case examples: http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top