title: Recyclerview with two lists and two view holders, onCreateViewHolder and onBind not called
body: <p>Hi I have the following code for my recycler view</p>
  <pre><code>package io.keepcoding.globaldisastertracker.ui.detail
  
  import android.content.Context
  import android.util.Log
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import androidx.recyclerview.widget.RecyclerView
  import com.bumptech.glide.Glide
  import com.bumptech.glide.request.RequestOptions
  import io.keepcoding.globaldisastertracker.R
  import kotlinx.android.synthetic.main.events_recycler_view_item.view.*
  import kotlinx.android.synthetic.main.images_recycler_view_item.view.*
  import kotlinx.android.synthetic.main.news_recycler_view_item.view.*
  
  class DetailAdapter(val context: Context, itemClickListener: DetailInteractionListener? = null) : RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;() {
  
      private var newsItems = mutableListOf&lt;NewsItemViewModel?&gt;()
      private var imagesItems = mutableListOf&lt;ImageItemViewModel?&gt;()
      private var isNewsFragment: Boolean = false
  
      private var newsDetailInteractionListener: ((View) -&gt; Unit)? = {
          if(it.tag is NewsItemViewModel){
              itemClickListener?.onNewsItemClick((it.tag as NewsItemViewModel)?.newsUrl as String)
          }
      }
      private var imagesDetailInteractionListener: ((View) -&gt;Unit)? = {
          if(it.tag is ImageItemViewModel){
              itemClickListener?.onImageItemClick((it.tag as ImageItemViewModel)?.image as String)
          }
      }
      companion object {
          const val NEWS = 1
          const val IMAGE = 2
      }
  
      fun setData(newsList: List&lt;NewsItemViewModel?&gt;?, imagesList: List&lt;ImageItemViewModel?&gt;?, isNews: Boolean){
          isNewsFragment = isNews
          if(isNewsFragment) {
              newsList?.let {
                  newsItems = it.toMutableList()
              }
          }
          else{
              imagesList?.let {
                  this.imagesItems = it.toMutableList()
              }
          }
          notifyDataSetChanged()
      }
  
      inner class NewsViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
          var article: NewsItemViewModel? = null
              set(value) {
                  field = value
                  itemView.tag = field
                  field?.let {
                      Glide.with(context)
                          .load(it.thumbnail)
                          .apply {
                              RequestOptions()
                                  .placeholder(R.drawable.ic_launcher_background)
  
                          }.into(itemView.news_image)
                      itemView.headline.text = it.title
                      itemView.content.text = it.description
                  }
              }
      }
  
      inner class ImagesViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
          var image: ImageItemViewModel? = null
              set(value) {
                  field = value
                  itemView.tag = field
                  field?.let {
                      Glide.with(context)
                          .load(it.image)
                          .apply {
                              RequestOptions()
                                  .placeholder(R.drawable.ic_launcher_background)
  
                          }.into(itemView.image)
                  }
              }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
          if(viewType == NEWS){
              return NewsViewHolder(LayoutInflater.from(context).inflate(R.layout.news_recycler_view_item, parent, false))
          }
          return ImagesViewHolder(LayoutInflater.from(context).inflate(R.layout.images_recycler_view_item, parent, false))
      }
  
      override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
          if(isNewsFragment){
              val article = newsItems?.get(position)
              (holder as NewsViewHolder).article = article
              holder.itemView.setOnClickListener(newsDetailInteractionListener)
          } else {
              val image = imagesItems?.get(position)
              (holder as ImagesViewHolder).image = image
              holder.itemView.setOnClickListener(imagesDetailInteractionListener)
          }
      }
  
      override fun getItemViewType(position: Int): Int {
          if(isNewsFragment){
              return newsItems?.get(position)!!.viewType
          }
          return imagesItems?.get(position)!!.viewType
      }
  
      override fun getItemCount(): Int {
          return if(isNewsFragment){
              newsItems!!.size
          } else imagesItems!!.size
      }
  }
  </code></pre>
  <p>And this is where I set the adapter in the fragment that contains it, I declared it lazily and then set it to the recyclerview's adapter after observing a live data variable from the view model.</p>
  <pre><code>package io.keepcoding.globaldisastertracker.ui.detail
  
  import android.os.Bundle
  import android.util.Log
  import androidx.fragment.app.Fragment
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.Toast
  import androidx.lifecycle.Observer
  import androidx.lifecycle.ViewModelProvider
  import androidx.recyclerview.widget.DividerItemDecoration
  import androidx.recyclerview.widget.GridLayoutManager
  import androidx.recyclerview.widget.LinearLayoutManager
  import com.google.android.material.floatingactionbutton.FloatingActionButton
  import io.keepcoding.globaldisastertracker.R
  import io.keepcoding.globaldisastertracker.repository.local.DisasterEventsRoomDatabase
  import io.keepcoding.globaldisastertracker.repository.local.LocalHelperImpl
  import io.keepcoding.globaldisastertracker.repository.remote.ApiHelperImpl
  import io.keepcoding.globaldisastertracker.repository.remote.RemoteDataManager
  import io.keepcoding.globaldisastertracker.ui.main.EventItemViewModel
  import io.keepcoding.globaldisastertracker.utils.CustomViewModelFactory
  import io.keepcoding.globaldisastertracker.utils.Status
  import kotlinx.android.synthetic.main.fragment_detail.list
  import kotlinx.android.synthetic.main.fragment_detail.loadingView
  import kotlinx.android.synthetic.main.fragment_detail.retry
  import kotlinx.android.synthetic.main.try_again.*
  
  // TODO: Rename parameter arguments, choose names that match
  // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
  private const val ARG_FROM_SERVER = &quot;FROM_SERVER&quot;
  private const val ARG_EVENT_ITEM = &quot;EVENT_ITEM&quot;
  private const val ARG_IS_NEWS_FRAGMENT =&quot;IS_NEWS_FRAGMENT&quot;
  
  
  /**
   * A simple [Fragment] subclass.
   * Use the [ListFragment.newInstance] factory method to
   * create an instance of this fragment.
   */
  class DetailFragment : Fragment() {
      // Fragment parameters
      private var fromServer: Boolean = false
      private var eventItem: EventItemViewModel? = null
      private var isNewsFragment: Boolean = false
      private var sharedFAB: FloatingActionButton? = null
  
      private var imageItems: List&lt;ImageItemViewModel?&gt;? = mutableListOf(null)
  
      private var newsItems: List&lt;NewsItemViewModel?&gt;? = mutableListOf(null)
  
      private val detailsAdapter: DetailAdapter by lazy {
          lateinit var adapter: DetailAdapter
          context?.let { context -&gt;
              adapter = DetailAdapter(context, requireActivity() as DetailActivity)
          }
          adapter.setData(newsItems, imageItems, isNewsFragment)
          adapter
      }
  
      private val viewModel: DetailFragmentViewModel by lazy {
          val factory = CustomViewModelFactory(requireActivity().application,
              ApiHelperImpl(RemoteDataManager().bingSearchApi, RemoteDataManager().eonetApi),
              LocalHelperImpl(DisasterEventsRoomDatabase.getInstance(requireActivity().applicationContext))
          )
          ViewModelProvider(this, factory).get(DetailFragmentViewModel::class.java)
      }
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          arguments?.let {
              fromServer = it.getBoolean(ARG_FROM_SERVER)
              eventItem = it.getParcelable(ARG_EVENT_ITEM)
              isNewsFragment = it.getBoolean(ARG_IS_NEWS_FRAGMENT)
          }
      }
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View? {
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_detail, container, false)
      }
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
          setUpListeners()
          setUpRecyclerView()
          setUpObservers()
      }
  
      fun setFABClickListener(fab: FloatingActionButton?){
          sharedFAB = fab
          if(fromServer){
              sharedFAB?.setOnClickListener {
                  eventItem?.let { eventItem -&gt;
                      viewModel.saveEvent(eventViewModel = eventItem)
                  }
              }
          } else {
              sharedFAB?.setOnClickListener {
                  eventItem?.let { eventItem -&gt;
                      viewModel.deleteEvent(eventItem.id!!)
                  }
              }
          }
      }
  
      private fun setUpListeners(){
          buttonRetry.setOnClickListener {
              eventItem?.let {
                  fetchData(it)
              }
          }
      }
  
      private fun setUpRecyclerView(){
          if(isNewsFragment){ // Display linear layout with news
              list.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
          } else { // Display grid layout with images
              list.layoutManager = GridLayoutManager(context, 3)
          }
          list.addItemDecoration(DividerItemDecoration(context, DividerItemDecoration.VERTICAL))
      }
  
      private fun fetchData(event: EventItemViewModel){
          if(fromServer){
              event.title?.let { title -&gt;
                  if(isNewsFragment) viewModel.fetchApiNews(title)
                  else viewModel.fetchApiImages(title)
              }
          } else {
              event.id?.let {id -&gt;
                  if(isNewsFragment) viewModel.loadNewsFromLocal(id)
                  else viewModel.loadImagesFromLocal(id)
              }
          }
      }
  
      private fun observeImages(){
          viewModel.getImages().observe(viewLifecycleOwner, Observer { images -&gt;
              when (images.status) {
                  Status.SUCCESS -&gt; {
                      imageItems = images.data
                      loadingView.visibility = View.INVISIBLE
                      list.visibility = View.VISIBLE
                      list.adapter = detailsAdapter
                  }
                  Status.LOADING -&gt; {
                      loadingView.visibility = View.VISIBLE
                      retry.visibility = View.INVISIBLE
                  }
                  Status.ERROR -&gt; {
                      retry.visibility = View.VISIBLE
                      loadingView.visibility = View.INVISIBLE
                      list.visibility = View.INVISIBLE
                  }
              }
          })
      }
  
      private fun observeNews(){
          viewModel.getNews().observe(viewLifecycleOwner, Observer { news -&gt;
              when (news.status) {
                  Status.SUCCESS -&gt; {
                      newsItems = news.data
                      loadingView.visibility = View.INVISIBLE
                      list.visibility = View.VISIBLE
                      list.adapter = detailsAdapter
                  }
                  Status.LOADING -&gt; {
                      retry.visibility = View.INVISIBLE
                      loadingView.visibility = View.VISIBLE
                      list.visibility = View.INVISIBLE
                  }
                  Status.ERROR -&gt; {
                      retry.visibility = View.VISIBLE
                      loadingView.visibility = View.INVISIBLE
                      list.visibility = View.INVISIBLE
                  }
              }
          })
      }
      private fun setUpObservers(){
          eventItem?.let { event -&gt;
              fetchData(event)
              if(isNewsFragment){
                  observeNews()
              } else {
                  observeImages()
              }
              viewModel.getSnackBar().observe(viewLifecycleOwner, Observer { snackBar -&gt;
                  when(snackBar.status) {
                      Status.SUCCESS -&gt; Toast.makeText(requireActivity().application, snackBar.data, Toast.LENGTH_LONG).show()
                      Status.ERROR -&gt; Toast.makeText(requireActivity().application, snackBar.message, Toast.LENGTH_LONG).show()
                  }
              })
          }
      }
  
  
      companion object {
          /**
           * Use this factory method to create a new instance of
           * this fragment using the provided parameters.
           *
           * @param param1 Parameter 1.
           * @param param2 Parameter 2.
           * @return A new instance of fragment ListFragment.
           */
          // TODO: Rename and change types and number of parameters
          @JvmStatic
          fun newInstance(fromServer: Boolean, eventItem : EventItemViewModel, isNewsFragment: Boolean) =
              DetailFragment().apply {
                  arguments = Bundle().apply {
                      putBoolean(ARG_FROM_SERVER, fromServer)
                      putBoolean(ARG_IS_NEWS_FRAGMENT, isNewsFragment)
                      putParcelable(ARG_EVENT_ITEM, eventItem)
  
                  }
              }
      }
  }
  </code></pre>
  <p>Github repo here
  <a href="https://github.com/AntonioRoldan/GlobalDisasterTracker" rel="nofollow noreferrer">https://github.com/AntonioRoldan/GlobalDisasterTracker</a></p>
  <p>UPDATE:
  I figured out that when using FrameLayout for the fragment the recycler view is shown, but not when it is LinearLayout, also when it is FrameLayout the tab layout is covered by the recycler view any idea why this is?</p>