Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change image onConfigurationChanged

Is there a way to change ImageView drawable with its corresponding drawable for landscape mode without destroying the whole activity. I tried to set the drawable again in onConfigurationChanged callback but it doesn't work. Something like this

@Override
public void onConfigurationChanged(Configuration conf) {
    super.onConfigurationChanged(conf);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.iv));
}

When i star the activity in landscape mode to correct drawable is displayed so resources are located correctly.

like image 470
Mojo Risin Avatar asked Jul 14 '10 09:07

Mojo Risin


1 Answers

In your sample project just replace

iv.setBackgroundResource(R.drawable.android);

with

iv.setImageDrawable(getResources().getDrawable(R.drawable.android));

I guess setBackgroundResource does nothing because the same resource is already assigned to ImageView.

Take a look at this
http://open-pim.com/tmp/ImageTest.zip
I tried your approach and it works just great for me.

like image 67
Fedor Avatar answered Oct 09 '22 06:10

Fedor