Lav Sharma
Lav Sharma

Reputation: 339

imageView.setVisibility(View.GONE); not working for ImageView

<ImageView
            android:id = "@+id/imageView"
            android:layout_width="200dp"
            android:layout_height="300dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp"
            android:layout_gravity="center"
            android:visibility="gone"
            android:src="@drawable/rectanglebutton"/>
url = list.get(position).getImageUrl();
            if(url == "null") {
                imageView.setVisibility(View.GONE);
                imageView.requestLayout();
            }
            else
            {
                imageView.setVisibility(View.VISIBLE);
                imageView.requestLayout();
                Glide
                        .with(DisplayQuestions.this)
                        .load(url)
                        .into(imageView);
            }

Upvotes: 0

Views: 489

Answers (3)

Usama Altaf
Usama Altaf

Reputation: 118

Try to check url string if its empty

if(url.getText().toString().isEmpty()){
   imageView.setVisibility(View.GONE);
   imageView.requestLayout();
}

Upvotes: 0

Saurabh Dhage
Saurabh Dhage

Reputation: 1711

url = list.get(position).getImageUrl();
            if(url == null) {
                imageView.setVisibility(View.GONE);
                imageView.requestLayout();
            }
            else
            {
                imageView.setVisibility(View.VISIBLE);
                imageView.requestLayout();
                Glide
                        .with(DisplayQuestions.this)
                        .load(url)
                        .into(imageView);
            }

null should not be inside double quote

Upvotes: 0

mrtubbs
mrtubbs

Reputation: 36

the problem seems to be in the java code.

try changing

if (url == "null")

to

if (url == null)
  • null should not be in doubble quotes.
  • and generally you should use "some_string".equals(object) to test strings.

Upvotes: 1

Related Questions