- I am trying to implement
imageView.setVisibility(View.GONE);if myURLisnullthen the visibility of theimageViewshould neGONEor else it should beVISIBLE. - In my
XMLI have defined it asandroid:visibility="gone"and if theURLis notnullthen I am displaying theimage. - The issue here is, it displays the image when it contains the url. But when the
urlisnullit is giving the empty space. - XML
<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"/>
- Java
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);
}
Advertisement
Answer
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.