I have a problem with changing colors in android.
I have a list where I add elements using:
colorsPictures.add(Color.BLUE);
colorsPictures.add(Color.YELLOW);
colorsPictures.add(Color.BLACK);
In onCreate() I implement some like this:
pictureOne.setImageResource(colorsPictures.get(0)));
pictureTwo.setImageResource(colorsPictures.get(1));
pictureOne and pictureTwo are:
pictureOne = (ImageView) findViewById(R.id.imageViewPicture1);
pictureTwo = (ImageView) findViewById(R.id.imageViewPicture2);
I want to both of my imageview change their color on blue and yellow when I start activity. I think that I have a bug in adding to my list. I know that I can change color in layout, but I must do this, this way. Help me pls.
For example:
I have two imageViews on layout. They have white colors. I want to change their colors when I run activity and I click the button. OnClick listener is implemented but I get nullpointexception when I try change colors.
The problem is that you are using
setImageResource(int resId)and the method argument is a drawable resource, not a color. If you look at your logs you will probably see a warning or exception saying that the resource is not found.You can use this instead: