title: How can I change in ViewModel source of my LiveData from Room Dao
body: <p>How can I change in ViewModel source of my LiveData from Room Dao.
  In WordDao I have two queries:</p>
  
  <pre><code>@Dao
  public interface WordDao {
  
     @Query("SELECT * FROM " + Word.TABLE_NAME + " ORDER BY text ASC")
     LiveData&lt;List&lt;Word&gt;&gt; getWordsByAsc();
  
     @Query("SELECT * FROM " + Word.TABLE_NAME + " ORDER BY text DESC")
     LiveData&lt;List&lt;Word&gt;&gt; getWordsByDesc();
  }
  </code></pre>
  
  <p>I have also Repository class:</p>
  
  <pre><code>public class WordRepository {
     public LiveData&lt;List&lt;Word&gt;&gt; getWordsByAsc() {
         return wordDao.getWordsByAsc();
     }
  
     public LiveData&lt;List&lt;Word&gt;&gt; getWordsByDesc() {
         return wordDao.getWordsByDesc();
     }
  }
  </code></pre>
  
  <p>and my ViewModel class:</p>
  
  <pre><code>public class WordViewModel extends AndroidViewModel {
      private boolean isSortAsc = true;
      private LiveData&lt;Word&gt; words;
      private WordRepository wordRepository;
  
      public WordViewModel(@NonNull Application application) {
          super(application);
  
          wordRepository = new WordRepository(application);
          words = wordRepository.getWordsByAsc();
      }
  
      public LiveData&lt;List&lt;Word&gt;&gt; getWords() {
         return words;
      }
  
      public void sortButtonClicked() {
         isSortAsc = !isSortAsc;
         //TODO how change here source of data depending on the isSortAsc
         //It works only after change configuration of screen, not insta
         words = isSortAsc ? wordRepository.getWordsByAsc() : 
              wordRepository.getWordsByDesc()
      }
  }
  </code></pre>
  
  <p>In my Activity I have added observer:</p>
  
  <pre><code> wordViewModel.getWords().observe(this, new Observer&lt;List&lt;Word&gt;&gt;() {
        @Override
        public void onChanged(@Nullable List&lt;Word&gt; words) {
            adapter.setWords(words);
        }
   });
  </code></pre>
  
  <p>In setWords(words) method I call also "notifyDataSetChanged()".</p>
  
  <p>How change in the viewModel class source of LiveData depending on the "isSortAsc" parameter
  (words = isSortAsc ? wordRepository.getWordsByAsc() : wordRepository.getWordsByDesc()</p>
  
  <p>It works only after change configuration of screen, not after insta change source for LiveData words</p>