title: How to apply LiveData to xxxFragment.class instead of XML
body: <p>How to apply <em>live data</em> <strong>isRefreshing</strong> to <code>swiperefreshLayout.isRefresh</code>?</p>
  <p>Code in <code>xxxViewModel.class</code>:</p>
  <pre><code>var isRefreshing = MutableLiveData&lt;Boolean&gt;()
  
  fun refresh() {
      viewModelScope.launch(Dispatchers.Main) {
          isRefreshing.value = true
  
          withContext(Dispatchers.IO) {
              fun doInBackground() // takes a long time
          }
     
          isRefreshing.value = false
      }
  }
  </code></pre>
  <p>Code in <code>xxxFragment.class</code>:</p>
  <pre><code>binding.swiperefreshLayout.setOnRefreshListener {
      xxxViewModel.refresh()
  }
  
  // error here, require Boolean, found MutableLiveData&lt;Boolean&gt;
  binding.swiperefreshLayout.isRefreshing = xxxViewModel.isRefreshing 
  </code></pre>
  <p>Usually I apply the live data to XML like below, but I cannot find <code>swiperefreshlayout.isRefreshing</code> in XML.</p>
  <pre><code>&lt;androidx.swiperefreshlayout.widget.SwipeRefreshLayout
          android:id=&quot;@+id/swiperefresh_layout&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;0dp&quot;
          isFreshing = &quot;@{xxxViewModel.isRefreshing}&quot;&gt;
  </code></pre>