1

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

V I J E S H
  • 7,464
  • 10
  • 29
  • 37
  • Hide the `ImageView`? Or remove the image from the `ImageView`? Try adding a few more specifics in the question. – Siddharth Lele Feb 18 '13 at 05:32
  • If you want to remove imageview completely you use removeView(view) but if you want to hide the image view you can use ImageView.setVisibility(ImageView.INVISIBLE) – Pragnani Feb 18 '13 at 05:37

3 Answers3

8

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);
Siddharth Lele
  • 27,623
  • 15
  • 98
  • 151
  • 1
    thanks for the "android.R.color.transparent" trick :) [incidentally, we have someone here who doesn't like to accept good answers] – dentex Aug 17 '16 at 14:36
2

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);
Renjith
  • 5,783
  • 9
  • 31
  • 42
1

Example:

LinearLayout linearLayout;
ImageView imageView;

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

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

Rowan Freeman
  • 15,724
  • 11
  • 69
  • 100