title: Android Firebase Database Automatic Refresh UPDATE 2
body: <p>I have implemented <code>Firebase Database</code> and can successfully add items to it and then display them on a <code>RecyclerView</code>. I also managed to implement Deletion of a child of a database which is successful BUT I need to restart activity to see changes on my phone's screen. For example: when I press Delete on my list item, it disappears from Database instantly but I need to restart the activity to see the change. Here is my code snippets:</p>
  
  <pre><code> private void attachDatabaseReadListener() {
  
      queryRef.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              locationCurrent = dataSnapshot.getValue(LocationCurrent.class);
              locationCurrent.setRefKey(dataSnapshot.getKey());
              mLocationAdapter.add(locationCurrent);
  
          }
  
          @Override
          public void onChildChanged(DataSnapshot dataSnapshot, String s) {
              locationCurrent = dataSnapshot.getValue(LocationCurrent.class);
  
  
          }
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
  
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  }
  </code></pre>
  
  <p>I believe I should work on <code>onChildRemoved</code> but have no idea where to start. My main Idea was to repopulate <code>recyclerview</code> using for loop but locationCurrent object I got from datasnapshot is null.</p>
  
  <p>Any ideas where should I start looking for solution? I have also considered to run <code>addValueEventListener</code> method on my query but I run into the problem where I get multiple copies of my single child</p>
  
  <p><strong><em>UPDATE</em></strong>
  Referring to some comments here is my adapter</p>
  
  <pre><code>public class LocationAdapter extends ArrayAdapter&lt;LocationCurrent&gt; {
  
  
  
  public LocationAdapter(Context context, int resource, List&lt;LocationCurrent&gt; objects) {
      super(context, resource, objects);
  }
  
  @NonNull
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      if (convertView == null) {
          convertView = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.item_location, parent, false);
      }
  
      LocationCurrent currentLocation = getItem(position);
  
      TextView nameTextView = (TextView) convertView.findViewById(R.id.nameTextView);
  
      TextView descriptionTextView = (TextView) convertView.findViewById(R.id.descriptionTextView);
  
  
      nameTextView.setText(currentLocation.getName());
      descriptionTextView.setText(currentLocation.getDescription());
  
  
  
      return convertView;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>By the way - my Ref Key which is used in locationCurrent class is transient variable and thus not visible in Database.</p>
  
  <p>UPDATE2</p>
  
  <p>After all day of working, I still did not manage to get the item off the adapter as soon it is deleted. Instead - I came up with a temporary solution - I added a <code>recreate()</code> method inside my <code>onChildRemoved</code> and it does it's job. (Not a good practice but still - something)</p>