title: Delete LiveData with Room onClick
body: <p>I have created a database using <code>LiveData</code> and <code>Room</code> following <a href="https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#0" rel="nofollow noreferrer">google codelabs</a> tutorial.</p>
  
  <p>Problem is I am unable to delete an entry with <code>onClick</code>.
  This is my <strong>Dao</strong></p>
  
  <pre><code>@Dao
  public interface PlacesDao {
    @Query("SELECT * from places_table ORDER BY place ASC")
    LiveData&lt;List&lt;Places&gt;&gt; getAllPlaces();
  //  LiveData&lt;List&lt;Word&gt;&gt; getAllWords();
  
  
    @Insert
    void insert(Places places);
  
    @Query("DELETE FROM places_table")
    void deleteAll();
  
    @Delete
    void deletePlace(Places places);
  }
  </code></pre>
  
  <p>And this is the <strong>ViewModel</strong></p>
  
  <pre><code>public class PlacesViewModel extends AndroidViewModel {
  
      private PlacesRepository mRepository;
      private LiveData&lt;List&lt;Places&gt;&gt; mAllWords;
  
      public PlacesViewModel (Application application) {
          super(application);
          mRepository = new PlacesRepository(application);
          mAllWords = mRepository.getAllPlaces();
      }
  
      LiveData&lt;List&lt;Places&gt;&gt; getAllWords() { return mAllWords; }
  
      public void insert(Places places) { mRepository.insert(places); }
  }
  </code></pre>
  
  <p>and here is the <strong>adapter</strong></p>
  
  <pre><code>public class PlacesAdapter extends RecyclerView.Adapter&lt;PlacesAdapter.PlacesViewHolder&gt; {
  
      class PlacesViewHolder extends RecyclerView.ViewHolder {
          public TextView place;
          public TextView lati;
          public TextView longi;
          public ImageView delbutton;
  
          private PlacesViewHolder(View itemView) {
              super(itemView);
              place = itemView.findViewById(R.id.placeLine);
              longi = itemView.findViewById(R.id.longLine);
              lati = itemView.findViewById(R.id.latiLine);
              delbutton = itemView.findViewById(R.id.delicon);
          }
      }
  
      private final LayoutInflater mInflater;
      private List&lt;Places&gt; mPlaces; // Cached copy of words
  
      PlacesAdapter(Context context) { mInflater = LayoutInflater.from(context); }
  
      @Override
      public PlacesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = mInflater.inflate(R.layout.places_list_item, parent, false);
          return new PlacesViewHolder(itemView);
      }
  
      @Override
      public void onBindViewHolder(PlacesViewHolder holder, final int position) {
        Places current = mPlaces.get(position);
        holder.place.setText(current.getPlace());
        holder.lati.setText(current.getLati());
        holder.longi.setText(current.getLongi());
        holder.delbutton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "DelButton Clisked", Snackbar.LENGTH_LONG).show();
            mPlaces.remove(position);
            Log.e("Adapter", String.valueOf(position));
          }
        });
      }
  
      void setPlaces(List&lt;Places&gt; places){
          mPlaces = places;
          notifyDataSetChanged();
      }
  
      // getItemCount() is called many times, and when it is first called,
      // mWords has not been updated (means initially, it's null, and we can't return null).
      @Override
      public int getItemCount() {
          if (mPlaces != null)
              return mPlaces.size();
          else return 0;
      }
  }
  </code></pre>
  
  <p>I know its not good to do <code>onClickListner</code> inside BindView, but this is the closest I can go. 
  On clicking the <code>delbutton</code>, both Snackber and Log is actvated, with <code>Log.e</code> is showing the expected value, but the item is not deleted.</p>
  
  <p>So, can someone kindly help me on how to do that?</p>
  
  <p>Regards,</p>
  
  <p><strong>Update</strong> The view is working, but I still cant delete rows from database. Any help please?</p>