Removing an Imageview from View

V I J E S H picture V I J E S H · Feb 18, 2013 · Viewed 12.1k times · Source

I want to remove an imageview from a View (android.view.View)based on a codition.condition is the src of that image view.How can i remove an imageView from a view. please help

Answer

Siddharth Lele picture Siddharth Lele · Feb 18, 2013

By remove if you mean hide the ImageView, based on a particular condition, do something like this:

if (your_condition) {
    your_image_view.setVisibility(View.GONE);
} else {
    your_image_view.setVisibility(View.VISISBLE);
}

If you need to remove the image currently set to the ImageView, do this in the if ... else above (based on the condition)

your_image_view.setImageResource(android.R.color.transparent); 

OR

your_image_view.setImageBitmap(null);

If you need to remove the ImageView completely, call this, in the if....else, on the ImageView's container:

container.removeView(your_image_view);