title: Kotlin RecyclerView + fragment add retrofit2 response from api, with Drawer menu
body: <p>I'm updating my knowledge of Android, and I want to make an app with a Drawer menu, call an api and display the values inside a fragment. Starting from the template created by android studio itself, I have followed this tutorial:<a href="https://howtodoandroid.com/mvvm-retrofit-recyclerview-kotlin/" rel="nofollow noreferrer">https://howtodoandroid.com/mvvm-retrofit-recyclerview-kotlin/</a>  but I have a problem when programming the MainActivity.
  Android studio template create this fragment (only changes the name of fragments):</p>
  <pre><code>class CheckListFragment : Fragment() {
  
  private var _binding: FragmentCheckListBinding? = null
  
  // This property is only valid between onCreateView and
  // onDestroyView.
  private val binding get() = _binding!!
  
  override fun onCreateView(
          inflater: LayoutInflater,
          container: ViewGroup?,
          savedInstanceState: Bundle?
  ): View {
      val checklistViewModel =
              ViewModelProvider(this).get(CheckListViewModel::class.java)
  
      _binding = FragmentCheckListBinding.inflate(inflater, container, false)
      val root: View = binding.root
  
      val textView: TextView = binding.textChecklist
      checklistViewModel.text.observe(viewLifecycleOwner) {
          textView.text = it
      }
      return root
  }
  
  override fun onDestroyView() {
      super.onDestroyView()
      _binding = null
  }
  </code></pre>
  <p>The issue is that I don't know how I should call the viewmodel in that section, since I've tried in different ways, reading and reading examples, but none is exactly what I need. If you need me to show more parts of the code (viewmodel, viewmodelfactory etc. I can add it without any problem, although they are practically the same as those described in the tutorial)
  In that example, in the MainActivity class we have this:</p>
  <pre><code>class MainActivity : AppCompatActivity() {
  private val TAG = &quot;MainActivity&quot;
  private lateinit var binding: ActivityMainBinding
  lateinit var viewModel: MainViewModel
  private val retrofitService = RetrofitService.getInstance()
  val adapter = MainAdapter()
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
      binding = ActivityMainBinding.inflate(layoutInflater)
      setContentView(binding.root)
      viewModel = ViewModelProvider(this, MyViewModelFactory(MainRepository(retrofitService))).get(MainViewModel::class.java)
      binding.recyclerview.adapter = adapter
      viewModel.movieList.observe(this, Observer {
          Log.d(TAG, &quot;onCreate: $it&quot;)
          adapter.setMovieList(it)
      })
      viewModel.errorMessage.observe(this, Observer {
      })
      viewModel.getAllMovies()
  }
  </code></pre>
  <p>But here not use fragments.
  I would greatly appreciate help, or a link where I can see an example of this</p>