title: Recycleview delete data - display data problem
body: <p>I have one question, I have a recycle view and inside it, I have some items that come from firebase database, when I press the button to delete the item, the item disappears from the dataset but the recycle view is displaying me the item that stands below the item that I just deleted and I don't understand why since I checked stack overflow on how to do it and I did the same thing but it's not working. </p>
  
  <p>I will add 3 photos and the code to explain myself better. </p>
  
  <ol>
  <li>First photo: The shopping list: I press on the ADD button, I added two items to the CHART.
  2  Second photo: I click on the delete button so I remove that item from the database but now it comes the problem the item below the item I just deleted appears in 2 places now : in the first place and in the second place, it's just like having 2 times the same item but is not true because if I go back to the shopping list and then I come back to the chart now everything is ok and I don't have the same item twice.</li>
  </ol>
  
  <p>Can anyone explain what's going on ?? I think it is a problem with the refresh of the recycle view but not sure 100%. </p>
  
  <p><a href="https://i.stack.imgur.com/EkdIu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EkdIu.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/s8JWG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s8JWG.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ydrd1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ydrd1.png" alt="enter image description here"></a></p>
  
  <p>Code: </p>
  
  <pre><code>   public class CartActivity extends AppCompatActivity implements  OnRemoveItemClickListener{
  
      private TextView total;
      private ImageButton removeFromCartt;
      private Button pay;
      private RecyclerView mResultList2;
      private DatabaseReference mUserDatabase;
      int i=0;
      int Totalprice=0;
      private UsersAdapter adapter;
      private ArrayList&lt;Users_get&gt; array_data = new ArrayList&lt;&gt;();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_cart);
          mUserDatabase = FirebaseDatabase.getInstance().getReference("Cart");
  
          total          = findViewById(R.id.TotalPrice);
          removeFromCartt = findViewById(R.id.removeFromCart);
          mResultList2    = findViewById(R.id.cartList);
          pay            = findViewById(R.id.pay);
  
          mResultList2.setHasFixedSize(true);
          mResultList2.setLayoutManager(new LinearLayoutManager(this));
  
  
          // Attach a listener to read the data at our posts reference
          mUserDatabase.addValueEventListener(new ValueEventListener() {
  
  
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  int flag=1;
                  for(DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
                      Users_get post = childSnapshot.getValue(Users_get.class);
                      array_data.add(new Users_get(post.getName(),post.getSurname(),post.getPrice(),childSnapshot.getKey()));
                      getTotalPrice(post.getPrice(),flag);
                  }
                  setAdapter();
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
                  System.out.println("The read failed: " + databaseError.getCode());
              }
  
          });
      }
  
      private void setAdapter() {
          adapter = new UsersAdapter(array_data,CartActivity.this);
          mResultList2.setAdapter(adapter);
      }
  
      public int getTotalPrice(Long price,int flag){
          if (array_data != null) {
              if(flag==1)
              {
                  Totalprice+=price;
              }
              else
                  {
                    Totalprice-=price;
                  }
          }
          System.out.println(Totalprice);
          return Totalprice;
      }
  
  
      @Override
      public void onRemoveItemClicked(final int position) {
          int flag=0;
          FirebaseDatabase.getInstance().getReference("Cart").child(array_data.get(position).getKey()).removeValue();
          getTotalPrice(array_data.get(position).getPrice(),flag);
          array_data.remove(position);
          adapter.notifyItemRemoved(position);
      }
  
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          if(adapter !=null){
              adapter.removeListener();
          }
      }
  }
  </code></pre>