Android - RecyclerView with one layout, multiple setVisibility

后端 未结 1 571
时光说笑
时光说笑 2020-12-07 04:13

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 a

相关标签:
1条回答
  • 2020-12-07 04:59

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

    // if no url is found from server
    if(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.

    0 讨论(0)
提交回复
热议问题