Write an Android app that displays these colors in a Spinner widget:
{"red", "orange", "yellow", "green",
"blue", "indigo", "violet"}
Add the Spinner items dynamically in the activity code. (Do you know about
the acronym ROYGBIV for remembering the colors of the rainbow?)
Also, after a color is selected and the linear layout is clicked, change the
background color of an ImageView widget to the color selected in the spinner.
Answer: Here are the layout and activity files:
activity_main.xml
MainActivity.java
This activity file uses Method 3 (anonymous class) to implement the click
event handler, when the user clicks on the linear layout. Next are the modified layout and activity
files that use Method 4 (lambda function) instead, when the user clicks on the
ImageView widget:
activity_main.xml
MainActivity.java