I have a spinner in my apps.
There are four items:-
item1
item2
item3
item4
I want to change background color of item1 and item4 only.
How can i set the background for these two items only.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Changing the element color
You will need to write your own custom
Adapterto do this job.getView()will be the method you are most interested in. There are lots of examples of how to write your own customAdapter.Here is an example from Vogella that is really good.
Basically do exactly what he did, change the
getView()to check what item it currently is and then set the back ground color for that particular elementView. He checked to see what item it was and then set an image for hisImageView. You would do the same, except change the background of yourTextView.If you can not figure this out, let me know. I will post a very simple custom
Adapterexample with what you are looking for.Changing the
SpinnercolorUse
mySpinner.setBackgroundColor(int color).And do a check to see what value is selected in the spinner and change the color depending on what value is currently there.
PsuedoCode