In AndroidStudio , I've made a list containing colors to select from using AlertDialog.builder
.
I stored the colors in charSequence like this CharSequence colors[] = new CharSequence[] {"Red1" , "Green1", "Blue1"};
so far so good.
Now I've made a class object1
that has an enum Color
defined like this
public class Object1 {
public enum Color {
Red, Green, Blue
}
private Color selectedColor;
public Object1 (Color color) {
this.selectedColor = color;
}
}
I want that whenever a color is selected from the AlertDialog a new instance of Object1 will be created with color chosen from the AlertDialog. meaning I need a way to convert charSequence into matching Color element (enum) and passed to objecgt1 constructor. How can I do this? I need to convert "Green1"
for example into Object1.Color.Green
I don't this that the ValueOf
method will help here since Green
and Green1
are different Strings Thank you