Reputation: 339
imageView.setVisibility(View.GONE);
if my URL
is null
then the visibility of the imageView
should ne GONE
or else it should be VISIBLE
.XML
I have defined it as android:visibility="gone"
and if the URL
is not null
then I am displaying the image
.url
is null
it is giving the empty space.<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
Reputation: 118
Try to check url string if its empty
if(url.getText().toString().isEmpty()){
imageView.setVisibility(View.GONE);
imageView.requestLayout();
}
Upvotes: 0
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
Reputation: 36
the problem seems to be in the java code.
try changing
if (url == "null")
to
if (url == null)
"some_string".equals(object)
to test strings.Upvotes: 1