title: Data binding with LiveData
body: <p>I am new to Architecture components and Data binding I am trying to update my Textview field in layout once i get response from API. Now my final response is in a Livedata like this:</p>
  
  <pre><code>  public class LoginViewModel @Inject constructor(var mApplication: Application, var repository: LoginRepository) :
  ViewModel() {
  
  
  var username: MutableLiveData&lt;String&gt; = MutableLiveData&lt;String&gt;()
  var password: MutableLiveData&lt;String&gt; = MutableLiveData&lt;String&gt;()
  var finalSet: MediatorLiveData&lt;WeatherData&gt; = MediatorLiveData()
  
  init {
      username.value = ""
      password.value = ""
      finalSet.addSource(repository.dataList) { it -&gt;
  
          finalSet.postValue(it)
      }
  }
  
      fun getWeatherData(): MediatorLiveData&lt;WeatherData&gt; {
  
  
  
  
          return finalSet
      }
  </code></pre>
  
  <p>and this is my layout file</p>
  
  <pre><code>    &lt;data&gt;
  
      &lt;variable
          name="loginViewModel"
          type="check.test.com.myapplication.login.LoginViewModel" /&gt;
      /&gt;
  
  
  &lt;/data&gt;
           &lt;TextView
               android:id="@+id/name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@{loginViewModel.}" /&gt;
  </code></pre>
  
  <p>This is my data class</p>
  
  <pre><code>      class WeatherData {
  
  
  @SerializedName("coord")
  var coord: Coord? = null
  @SerializedName("sys")
  var sys: Sys? = null
  @SerializedName("weather")
  var weather = ArrayList&lt;Weather&gt;()
  @SerializedName("main")
  var main: Main? = null
  @SerializedName("wind")
  var wind: Wind? = null
  @SerializedName("rain")
  var rain: Rain? = null
  @SerializedName("clouds")
  var clouds: Clouds? = null
  @SerializedName("dt")
  var dt: Float = 0.toFloat()
  @SerializedName("id")
  var id: Int = 0
  @SerializedName("name")
  var name: String? = null
  @SerializedName("cod")
  var cod: Float = 0.toFloat()
    }
  
    class Weather {
  @SerializedName("id")
  var id: Int = 0
  @SerializedName("main")
  var main: String? = null
  @SerializedName("description")
  var description: String? = null
  @SerializedName("icon")
  var icon: String? = null
   }
  
  class Clouds {
  @SerializedName("all")
  var all: Float = 0.toFloat()
    }
  
    class Rain {
  @SerializedName("3h")
  var h3: Float = 0.toFloat()
   }
  
    class Wind {
  @SerializedName("speed")
  var speed: Float = 0.toFloat()
  @SerializedName("deg")
  var deg: Float = 0.toFloat()
  }
  
  class Main {
  @SerializedName("temp")
  var temp: Float = 0.toFloat()
  @SerializedName("humidity")
  var humidity: Float = 0.toFloat()
  @SerializedName("pressure")
  var pressure: Float = 0.toFloat()
  @SerializedName("temp_min")
  var temp_min: Float = 0.toFloat()
  @SerializedName("temp_max")
  var temp_max: Float = 0.toFloat()
   }
  
   class Sys {
  @SerializedName("country")
  var country: String? = null
  @SerializedName("sunrise")
  var sunrise: Long = 0
  @SerializedName("sunset")
  var sunset: Long = 0
   }
  
   class Coord {
  @SerializedName("lon")
  var lon: Float = 0.toFloat()
  @SerializedName("lat")
  var lat: Float = 0.toFloat()
   }
  </code></pre>
  
  <p>Now what i want is that once i have the data in finalSet variable the Textview text should be updated.</p>
  
  <p>I thought of doing it this way:</p>
  
  <pre><code>         &lt;data&gt;
  
      &lt;variable
          name="loginViewModel"
          type="check.test.com.myapplication.login.LoginViewModel" /&gt;
      /&gt;
  
      &lt;variable
          name="data"
          type="check.test.com.myapplication.login.WeatherData" /&gt;
      /&gt;
  
  
  &lt;/data&gt;
  </code></pre>
  
  <p>and giving value to data element in Activity observer like this</p>
  
  <pre><code>    viewModel.getWeatherData().observe(this, Observer { data -&gt;
  
  
          binding.data = data
  
         // startActivity(Intent(this, MainActivity::class.java))
  
  
      })
  </code></pre>
  
  <p>I am aware of using observable fields and do this. I am also aware that this can also be done if i pass this property to a new variable and assign it in layout file but i want to understand the best practice to do this.</p>
  
  <p>I have tried following many blogs and few questions available here but none of them is helping with the best way of doing this.</p>
  
  <p>Requesting everyone here to enlighten the path. Thanks in advance.</p>