title: How can I make one ViewModel class return multiple data types to an activity or a fragment
body: <p>I'm reading this blog post <a href="https://firebase.googleblog.com/2017/12/using-android-architecture-components_20.html" rel="nofollow noreferrer" title="Using Android Architecture Components with Firebase Realtime Database &#40;Part 2&#41;">Using Android Architecture Components with Firebase Realtime Database (Part 2) </a> and I'm implementing the last code snippet, and its working. </p>
  
  <pre><code>private final FirebaseQueryLiveData liveData = new FirebaseQueryLiveData(HOT_STOCK_REF);
  private final MediatorLiveData&lt;HotStock&gt; hotStockLiveData = new MediatorLiveData&lt;&gt;();
  
  public HotStockViewModel() {
      // Set up the MediatorLiveData to convert DataSnapshot objects into HotStock objects
      hotStockLiveData.addSource(liveData, new Observer&lt;DataSnapshot&gt;() {
          @Override
          public void onChanged(@Nullable final DataSnapshot dataSnapshot) {
              if (dataSnapshot != null) {
                  new Thread(new Runnable() {
                      @Override
                      public void run() {
                          hotStockLiveData.postValue(dataSnapshot.getValue(HotStock.class));
                      }
                  }).start();
              } else {
                  hotStockLiveData.setValue(null);
              }
          }
      });
  }
  </code></pre>
  
  <p>I'm actually using it to return an array of HotStockViewModel objects wrapped in LiveData (by looping through the result from the database and I really don't know if I should be doing this data manipulation in a ViewModel class) and returning the array to a fragment which just displays it.</p>
  
  <p>Is it possible to use this same ViewModel class to return an array of only the prices wrapped in LiveData (and still also return an array of the HotStockViewModel objects wrapped in LiveData)? </p>
  
  <p>If it is, how can I achieve  this? I don't want to return an array of the HotStockViewModel objects wrapped in LiveData and then loop through it to get the prices in a fragment. I don't want the fragment to do any data manipulation at all, only display data.</p>
  
  <p>I saw this stackoverflow question <a href="https://stackoverflow.com/questions/46434196/can-an-android-architecture-components-viewmodel-compose-an-object-from-multiple">Can an Android Architecture Components ViewModel compose an object from multiple LiveData returning models?</a>  but I don't understand the answer. I'm still a Java beginner.</p>