Reputation: 7594
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
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
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
Reputation: 16348
Example:
LinearLayout linearLayout;
ImageView imageView;
if (condition) {
linearLayout.removeView(imageView);
}
I'd need more information to provide a better answer.
Upvotes: 1