title: android my viewModel update the list internally but recyclerview does't reflects the changes
body: <p>I'm trying to view my files using recycler view and MVVM, the problem is that <code>memoryViewModel</code> doesn't reflect the changes on <code>memoryItemsRecyclerViewAdapter</code></p>
  <pre><code>memoryViewModel!!.mutableLiveData?.observe(this.viewLifecycleOwner) {
              memoryItemsRecyclerViewAdapter.notifyDataSetChanged() //this should show the list items of the recycler view
              Log.d(&quot;view model result&quot;, it.size.toString()) // log message shows the list items
          }
  </code></pre>
  <p>so, the final question is why the <code>mutableLiveData!!.postValue(mutableList)</code> don't update the recycler view?
  here is a sample of my code</p>
  <p>the fragment</p>
  <pre><code>class MemoryFragment: Fragment() {
      companion object{
          private var rootDirectory: java.io.File? = null
          var currentFolder = rootDirectory
          private var filesList: MutableList&lt;File?&gt;? = mutableListOf()
          private var memoryViewModel: MemoryViewModel? = null
      }
      private var sharedPreferences: SharedPreferences? = null
      private lateinit var listView: RecyclerView
      private lateinit var pathsRecyclerView: RecyclerView
      private lateinit var searchView: androidx.appcompat.widget.SearchView
      private lateinit var refreshSwipe: SwipeRefreshLayout
      private lateinit var memoryItemsRecyclerViewAdapter: MemoryItemsRecyclerViewAdapter
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          sharedPreferences = androidx.preference.PreferenceManager
              .getDefaultSharedPreferences(requireContext())
  
          val memoryViewModelProvider = MemoryViewModelProvider()
          memoryViewModel = ViewModelProvider(this, memoryViewModelProvider).get(MemoryViewModel::class.java)
          
  //        rootDirectory = Environment.getExternalStorageDirectory()
  //        currentFolder = rootDirectory
  //        val rootFoldersList = rootDirectory?.listFiles()?.toMutableList()
  //        for (item in rootFoldersList!!)
  //            if(item.isDirectory)
  //                filesList?.add(File(R.drawable.ic_folders, item, item.totalSpace))
  //            else
  //                filesList?.add(File(R.drawable.ic_file, item, item.totalSpace))
  //        memoryViewModel = MemoryViewModel(filesList!!)
  //        MemoryViewModel.lazyMemoryViewModel
      }
      
      override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          val view = LayoutInflater.from(requireContext()).inflate(R.layout.fragment_memory, container, false)
          listView = view.findViewById(R.id.list_view)
          pathsRecyclerView = view.findViewById(R.id.recycler_view)
          searchView = view.findViewById(R.id.search_view)
          refreshSwipe = view.findViewById(R.id.swipe_refresh)
          listView.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
  
          memoryItemsRecyclerViewAdapter = MemoryItemsRecyclerViewAdapter(memoryViewModel!!, requireContext(), filesList!!)
  
          listView.adapter = memoryItemsRecyclerViewAdapter
  
          memoryViewModel!!.mutableLiveData?.observe(this.viewLifecycleOwner) {
              memoryItemsRecyclerViewAdapter.notifyDataSetChanged()
              Log.d(&quot;view model result&quot;, it.size.toString())
  
          }
          return view
      }
  }
  </code></pre>
  <p>the viewModel</p>
  <pre><code>class MemoryViewModel(private var mutableList: MutableList&lt;com.example.everyentertainment.models.File?&gt;?): ViewModel() {
  private val foldersPath: MutableList&lt;String?&gt;? = null
  private val foldersName: MutableList&lt;String?&gt;? = null
  private var rootDirectory: File? = null
  var mutableLiveData: MutableLiveData&lt;MutableList&lt;com.example.everyentertainment.models.File?&gt;&gt;? = null
  
  companion object{
      var currentFolder: File? = null
  }
  
  init {
      val job = viewModelScope.launch(Dispatchers.IO) {
          if (mutableLiveData == null) mutableLiveData = MutableLiveData()
          if(mutableList == null) mutableList = mutableListOf()
          initializeMemoryFragment()
      }
      job.start()
      job.invokeOnCompletion {
          mutableLiveData!!.postValue(mutableList)//postValue() doesn't update UI also I tried mutableLiveData.value = mutableList but it throws OnCompletionHandlerException
          Log.d(&quot;mutable list size&quot;, mutableList!!.size.toString())
          Log.d(&quot;mutable live data size&quot;, mutableLiveData!!.value.toString())
      }
  }
  
  fun initializeMemoryFragment(){
      rootDirectory = getExternalStorageDirectory()
      currentFolder = rootDirectory
      val filesList = rootDirectory!!.listFiles()
      for(position in filesList!!.indices)
          if(filesList[position].isDirectory)
              mutableList!!.add(com.example.everyentertainment.models.File(R.drawable.ic_folders,
                  filesList[position], getFolderSize(filesList[position])))
          else
              mutableList!!.add(com.example.everyentertainment.models.File(R.drawable.ic_file,
                  filesList[position], getFolderSize(filesList[position])))
  }
  
   fun getFolderSize(file: File): Long{
      if(!file.exists())
          return 0
      if(!file.isDirectory)
          return file.length()
      val dirs: MutableList&lt;File&gt; = LinkedList()
      dirs.add(file)
      var result: Long = 0
      while (!dirs.isEmpty()) {
          val dir = dirs.removeAt(0)
          if (!dir.exists()) continue
          val listFiles = dir.listFiles()
          if (listFiles == null || listFiles.isEmpty()) continue
          for (child in listFiles) {
              result += child.length()
              if (child.isDirectory) dirs.add(child)
          }
      }
      return result
  }
  </code></pre>
  <p>and finally the recycler view adapter</p>
  <pre><code>class MemoryItemsRecyclerViewAdapter(private val memoryViewModel: MemoryViewModel, private val context: Context, private val dataSet: MutableList&lt;File?&gt;?):
  RecyclerView.Adapter&lt;MemoryItemsRecyclerViewAdapter.ViewHolder&gt;() {
  /**
   * Provide a reference to the type of views that you are using
   * (custom ViewHolder).
   */
  class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
      val fileNameTextView: TextView = view.findViewById(R.id.name_text_view)
      val sizeTextView: TextView = view.findViewById(R.id.size_text_view)
      val numberOfFilesTextView: TextView = view.findViewById(R.id.number_of_files_text_view)
      val dateTextView: TextView = view.findViewById(R.id.date_text_view)
      val imageView: ImageView = view.findViewById(R.id.image_view)
  
      init {
      // Define click listener for the ViewHolder's View.
  
      }
  }
  
  // Create new views (invoked by the layout manager)
  override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
      // Create a new view, which defines the UI of the list item
      val view = LayoutInflater.from(viewGroup.context).inflate(R.layout.memory_list_view_item, viewGroup, false)
      return ViewHolder(view)
  }
  
  // Replace the contents of a view (invoked by the layout manager)
  override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
      // Get element from your dataset at this position and replace the
      // contents of the view with that element
      val file = dataSet!![position]
      viewHolder.fileNameTextView.text = file!!.file.name
      viewHolder.sizeTextView.text = memoryViewModel.readableFileSize(dataSet[position]!!.size)
      viewHolder.dateTextView.text = memoryViewModel.getFolderDateModified(file.file)
      viewHolder.numberOfFilesTextView.text = memoryViewModel.getSubFoldersQuantity(context, file.file)
      if(file.file.isDirectory)
          viewHolder.imageView.setImageResource(R.drawable.ic_folders)
      else
          viewHolder.imageView.setImageResource(R.drawable.ic_file)
  }
  
  // Return the size of your dataset (invoked by the layout manager)
  override fun getItemCount() = dataSet!!.size
  </code></pre>
  <p>}</p>