title: How to add Items to RecyclerView using a ViewModel Android Kotlin
body: <p>I have a <code>fragment</code> in which a <code>RecyclerView</code> is initialized. In the same <code>fragment</code>, I add elements to this <code>RecyclerView</code>. Code below:</p>
  <pre><code>private lateinit var profileMenuList: MutableList&lt;ProfileMenu&gt;
  
      override fun onCreateView(
          inflater: LayoutInflater, container: ViewGroup?,
          savedInstanceState: Bundle?
      ): View {
          _binding = FragmentProfileBinding.inflate(inflater, container, false)
  
          return binding.root
      }
  
      override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
          super.onViewCreated(view, savedInstanceState)
  
          setupRecyclerView()
      }
  
      private fun setupRecyclerView() {
          profileMenuList = mutableListOf(
              ProfileMenu(
                  title = &quot;Favorite&quot;,
                  description = &quot;What you liked&quot;,
                  icon = R.drawable.ic_outline_favorite_light
              )
          )
          
          val adapter = ProfileAdapter(profileMenuList)
          binding.rvProfileMenu.layoutManager = LinearLayoutManager(requireContext())
          binding.rvProfileMenu.adapter = adapter
      }
  </code></pre>
  <p>Here is also the code for the <code>Adapter</code>:</p>
  <pre><code>class ProfileAdapter(private val profileMenuList: List&lt;ProfileMenu&gt;): RecyclerView.Adapter&lt;ProfileAdapter.ViewHolder&gt;() {
  
      class ViewHolder(private val binding: ItemProfileMenuBinding): RecyclerView.ViewHolder(binding.root) {
          fun bind(menu: ProfileMenu) = with(binding) {
              tvTitle.text = menu.title
              tvDescription.text = menu.description
              Glide.with(itemView.context).load(menu.icon).into(ivIcon)
          }
  
          companion object {
              fun from(parent: ViewGroup): ViewHolder {
                  val layoutInflater = LayoutInflater.from(parent.context)
                  val binding = ItemProfileMenuBinding.inflate(layoutInflater, parent, false)
                  return ViewHolder(binding)
              }
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          return ViewHolder.from(parent)
      }
  }
  </code></pre>
  <p>But I want to put the code from the <code>setupRecyclerView()</code> function, which is in the <code>fragment</code>, into the view model. How can i do this?</p>