Skip to content Skip to sidebar Skip to footer

Android - Recyclerview With One Layout, Multiple Setvisibility

I have a basically all in one layout which has everything needed for my app's main feed. All variable items (images, video thumbnails.. Etc.) are set to GONE at first and set to VI

Solution 1:

You need to put the else condition too. Like the example below.

// if no url is found from serverif(url == null){
  ((ObjectViewHolder) holder).userPostImageWrapper.setVisibility(View.GONE);
  ((ObjectViewHolder) holder).userPostYoutubeImageWrapper.setVisibility(View.GONE);

} else {
  // Some url has found 
  ((ObjectViewHolder) holder).userPostImageWrapper.setVisibility(View.VISIBLE);
  ((ObjectViewHolder) holder).userPostYoutubeImageWrapper.setVisibility(View.VISIBLE);
}

Do this for each of the items you've got there as the list item in case of you're setting their visibilities in runtime.

Solution 2:

All your if conditions in onBindViewHolder() must have an else block too.

Don't leave any if condition without else. You can provide a default behaviour in the else block when if condition becomes false.

Post a Comment for "Android - Recyclerview With One Layout, Multiple Setvisibility"