Dmitry Zaytsev
Dmitry Zaytsev

Reputation: 23952

How to clear ImageView correctly?

For example, in my Activity I have such code (I skip the initialization of variables):

ImageView iview; //some ImageView
Bitmap b; //some Bitmap
iview.setImageBitmap(b);

Question is - how to clear iview resources correctly (with or without destroying view) ? Would ImageView free it's resources (used in native code) after b.recycle()?

I suppose, that ImageView doesn't just free it resources after Activity onStop (or onDestroy).

Upvotes: 14

Views: 37021

Answers (5)

Syed Danish Haider
Syed Danish Haider

Reputation: 1384

if nothing is working for you try setting the background color of view to layout color.if my layout color is white u can do like this:

 edit_countflag.setBackgroundColor(Color.parseColor("#ffffff"));
//then set the image
 edit_countflag.setImageResource(R.drawable.flag_id);

Upvotes: 0

Dhiraj Singh
Dhiraj Singh

Reputation: 171

You can use frequently it works:

imageView.setImageResource(0);

Upvotes: 1

Ashraf Alshahawy
Ashraf Alshahawy

Reputation: 1189

viewToUse.setImageResource(android.R.color.transparent);
  • I think using setImageResource with a color identifier will give you crashing issues on Android 2.2.1, make sure to test it.

Upvotes: 0

Samir Mangroliya
Samir Mangroliya

Reputation: 40406

imgview.setImageResource(0);

or

imgview.setImageDrawable(null);

Upvotes: 42

jeet
jeet

Reputation: 29199

no you need to unbindDrawables, you can do it by setting iview.setImageDrawable(null);

Upvotes: 5

Related Questions