Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android hide and removing the image in imageview

How to remove a image in imageview in android and also how to hide the entire image.

Here I have placed an image in imageview by the below code.

answerState1.setBackgroundResource(R.drawable.correct);

I don't know how to remove or hide the image. Also I am entirely new to android development.

like image 789
nik Avatar asked Jul 12 '11 10:07

nik


People also ask

How do you delete pictures on android?

I used setImageBitmap()/setImageResource() alternatively for same imageview depending on the conditions. Hence I had to use setImageResource(0)/setImageBitmap(null) alternativley to clear the imageview. Thanks!


2 Answers

You can set the visibility of an image with the following method calls:

answerState1.setVisibility(View.GONE);  // hide image (make the view gone)

answerState1.setVisibility(View.VISIBLE);  // make image visible

answerState1.setVisibility(View.INVISIBLE);  // make image invisible

In UI, you can also do something like the following:

<ImageView android:id="@+id/imgPreview" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
android:visibility="gone"/>
like image 100
jennifer Avatar answered Sep 19 '22 14:09

jennifer


try this imageview.setVisibility(ImageView.INVISIBLE);

like image 23
Taruni Avatar answered Sep 21 '22 14:09

Taruni