title: How do I show all the items in the favorites list using the room database?
body: <p>By examining various examples, I added to favorites when the item on Recyclerview was clicked. But I have a problem and I couldn't fix it.</p>
  
  <p>When I click on add favorite, the item goes to the favorites list, but the last item I clicked is on the list. I want all the elements I click to appear in the list.</p>
  
  <p>My Dao class</p>
  
  <pre><code>@Insert(onConflict = OnConflictStrategy.REPLACE)
  void insert(Country country);
  
  @Delete
  void delete(Country country);
  
  @Query("SELECT * FROM followed_country")
  LiveData&lt;List&lt;Country&gt;&gt; getAllFavoriteCountries();
  </code></pre>
  
  <p>My click method in my adapter class</p>
  
  <pre><code>    mListItemBinding.imgFollowedCountry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                  int position = getLayoutPosition();
                  final Country country = countryList.get(position);
                  if (isChecked &amp;&amp; !isCountryFavorite(country)) {
                      final CountryDatabase db = CountryDatabase.getInstance(context);
                      AppExecutors.getInstance().diskIO().execute(new Runnable() {
                          @Override
                          public void run() {
                              Log.e("EKLENDİ", "EKLENDİİİİİ");
                              db.countryDao().insert(country);
                          }
                      });
                      mListItemBinding.imgFollowedCountry.setChecked(true);
                  } else if (!isChecked) {
                      final CountryDatabase db = CountryDatabase.getInstance(context);
                      AppExecutors.getInstance().diskIO().execute(new Runnable() {
                          @Override
                          public void run() {
                              db.countryDao().delete(country);
                          }
                      });
                      mListItemBinding.imgFollowedCountry.setChecked(false);
                  }
              }
          });
  </code></pre>
  
  <p>FavoriteActivity class</p>
  
  <pre><code>    FavoriteViewModel viewModel = ViewModelProviders.of(this).get(FavoriteViewModel.class);
      viewModel.getFavoriteCountry().observe(this, new Observer&lt;List&lt;Country&gt;&gt;() {
          @Override
          public void onChanged(List&lt;Country&gt; countryList) {
              adapter.setCountry(countryList);
              Log.e("MAİNN", ""+countryList.size());
          }
      });
  </code></pre>
  
  <p>FavoriteViewModel Class</p>
  
  <pre><code>private LiveData&lt;List&lt;Country&gt;&gt; country;
  
  public FavoriteViewModel(@NonNull Application application) {
      super(application);
      CountryDatabase db = CountryDatabase.getInstance(this.getApplication());
      country = db.countryDao().getAllFavoriteCountries();
  }
  
  public LiveData&lt;List&lt;Country&gt;&gt; getFavoriteCountry(){
      return country;
  }
  </code></pre>
  
  <p>Some screenshots</p>
  
  <p><a href="https://i.stack.imgur.com/4L7Z3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4L7Z3.png" alt="I added 2 items to my favorites on the list"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Hbz8y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hbz8y.png" alt="But only the last item I added is visible"></a></p>