문제

I have an ImageView initialized with an image. Then in java when process accept some condition I want to change the picture. I made this code

if(i==1)
{
    ImageView imgv = (ImageView) findViewById(R.id.imageView2);
    imgv=setImageResource(R.drawable.player1);
}

But I get an error in java saying the method setImageResource() is undefined in the type javaFile. What does that mean? How to overcome this error? Is there any better way for changing an image like the way I wanted?

도움이 되었습니까?

해결책

Try:

imgv.setImageResource(R.drawable.player1);

Instead of:

imgv=setImageResource(R.drawable.player1);

Because setImageResource is a method of the ImageView.

다른 팁

you should be calling imgv.setImageResource(R.drawable.player1);, note the period character, you have used an equals character.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top