V I J E S H
V I J E S H

Reputation: 7594

Removing an Imageview from View

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

Upvotes: 1

Views: 13484

Answers (3)

Siddharth Lele
Siddharth Lele

Reputation: 27748

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);

Upvotes: 8

Renjith
Renjith

Reputation: 5803

To remove the imageview, use

if(condition) {
     imageView.setVisibility(View.GONE);
}

To make the imageview hide/invisible, use

if(condition) {
     imageView.setVisibility(View.INVISIBLE);
}

To bring back the imageview, use

imageView.setVisibility(View.VISIBLE);

Upvotes: 2

Rowan Freeman
Rowan Freeman

Reputation: 16348

Example:

LinearLayout linearLayout;
ImageView imageView;

if (condition) {
    linearLayout.removeView(imageView);
}

I'd need more information to provide a better answer.

Upvotes: 1

Related Questions