title: Reload fragment/activity (or recyclerview) from adaptater
body: <p>I have a simple app with fragment and activity hosting a recyclerview, vith data fom a database, i have a delete function, but i can't refresh the recycler view, i tried some method but because my longclick cardview is on the adapter, i can't make it work</p>
  
  <p>this is my adapter:</p>
  
  <pre><code>public class LoyaltyCardRVAdapter extends RecyclerView.Adapter&lt;LoyaltyCardRVAdapter.CardViewHolder&gt; {
  
  ...
  
  public LoyaltyCardRVAdapter(Context context, ArrayList&lt;LoyaltyCardObject&gt; cards) {
      this.context = context;
      this.cards = cards;
  }
  
  public void setData(ArrayList&lt;LoyaltyCardObject&gt; cards) {
      this.cards = cards;
  }
  
  @Override
  public int getItemCount() {
      return cards.size();
  }
  
  @Override
  public void onBindViewHolder(CardViewHolder holder, int position) {
      LoyaltyCardObject card = cards.get(position);
  
      holder.marque.setText(card.getMarque());
      ...
  }
  
  @Override
  public CardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.loyaltycard_row,
              parent, false);
      return new CardViewHolder(view, context, cards);
  }
  
  
  /**
   * Cette classe initialise chaque cardview avec l'object correspondant
   */
  public static class CardViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
      CardView cardView;
      TextView mail, marque, code;
      ArrayList&lt;LoyaltyCardObject&gt; cards = new ArrayList&lt;&gt;();
      Context context;
      AlertDialog.Builder alertDialogBuilder;
      RequestQueue requestQueue;
      ImageView logo;
  
      public CardViewHolder(View view, Context context, ArrayList&lt;LoyaltyCardObject&gt; cards) {
          ...
      }
  
      @Override
      public void onClick(View v) { //Gère le clique sur une cardview
  
          int position = getAdapterPosition();
          LoyaltyCardObject card = this.cards.get(position);
          Toast.makeText(context, "Codebarre pour la carte " + card.getMarque(), Toast.LENGTH_SHORT).show();
          Intent intentcode = new Intent(this.context.getApplicationContext(), LoyaltyCardShowCodeActivity.class);
          intentcode.putExtra("code", card.getCode());
          this.context.startActivity(intentcode);
      }
  
      @Override
      public boolean onLongClick(View v) {
  
          int position = getAdapterPosition();
          final LoyaltyCardObject card = this.cards.get(position);
          requestQueue = Volley.newRequestQueue(context);
  
  
          alertDialogBuilder
                  .setTitle("Effacer")
                  .setMessage("Voulez-vous vraiment effacer cette carte ?")
                  .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.cancel();
  
                          StringRequest request = new StringRequest(Request.Method.POST, url,
                                  new Response.Listener&lt;String&gt;() {
                                      @Override
                                      public void onResponse(String response) {
                                          Toast.makeText(context, "Carte n°" + card.getCode() + " chez " + card.getMarque() + " effacé", Toast.LENGTH_SHORT).show();
                                      }
                                  }, new Response.ErrorListener() {
                              @Override
                              public void onErrorResponse(VolleyError error) {
                                  Log.i("MYAPP", "onErrorResponse()");
                              }
                          }) { // Paramètres de la requete
                              @Override
                              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                                  Map&lt;String, String&gt; parameters = new HashMap&lt;String, String&gt;();
                                  parameters.put("mail", card.getMail());
                                  parameters.put("code", card.getCode());
                                  return parameters;
                              }
                          };
                          requestQueue.add(request);
                      }
                  })
                  .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {
                          dialog.cancel();
                      }
                  })
                  .setIcon(R.drawable.ic_error_outline_black_24dp)
                  .show();
          return false;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my fragment in this exemple:</p>
  
  <pre><code>public class LoyaltyCardListFragment extends android.support.v4.app.Fragment {
  
  LoyaltyCardRVAdapter adapter;
  ProgressDialog dialog;
  TextView addCards;
  UserSharedPreferences userSharedPreferences;
  ArrayList&lt;LoyaltyCardObject&gt; cards = new ArrayList&lt;LoyaltyCardObject&gt;();
  String url = ServerURL.CARD_GET;
  AlertDialog.Builder builder;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View rootView = inflater.inflate(R.layout.loyaltycard_list_fragment, container, false);
      RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_cards);
      recyclerView.setHasFixedSize(true);
      adapter = new LoyaltyCardRVAdapter(getActivity(), cards);
      LinearLayoutManager llm = new LinearLayoutManager(getActivity());
      llm.setOrientation(LinearLayoutManager.VERTICAL);
      recyclerView.setHasFixedSize(true);
      recyclerView.setLayoutManager(llm);
      recyclerView.setAdapter(adapter);
  
      addCards = (TextView) rootView.findViewById(R.id.addCards);
  
      adapter.setData(cards);
  
      dialog = new ProgressDialog(getActivity());
      dialog.setMessage("Chargement");
      dialog.setCancelable(true);
      showDialog();
  
      addCards.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              builder = new AlertDialog.Builder(getActivity());
              builder.setTitle("Ajout de carte");
              builder.setMessage("Comment ajouter ?");
              builder.setPositiveButton("Scanner", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                      Log.i("Alert", "YES");
                      Intent intent = new Intent(getActivity(), LoyaltyCardAddWithScannerActivity.class);
                      startActivity(intent);
                  }
              });
              builder.setNegativeButton("Manuel", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                      Log.i("Alert", "NO");
                      startActivity(new Intent(getActivity(), LoyaltyCardAddActivity.class));
                  }
              });
              AlertDialog alertDialog = builder.create();
              alertDialog.show();
          }
      });
  
      getAndInitData();
  
      return rootView;
  }
  
  public void getAndInitData() { //Recupère les cartes de l'utilisateur et les affiches dans un recycler view sous forme de cardview
  
      userSharedPreferences = new UserSharedPreferences(getActivity());
      final UserObject user = userSharedPreferences.getLoggedInUser();
  
      JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url + user.mail,
              new Response.Listener&lt;JSONArray&gt;() {
                  @Override
                  public void onResponse(JSONArray response) {
                      try {
                          for (int i = 0; i &lt; response.length(); i++) {
                              JSONObject object = response.getJSONObject(i);
                              LoyaltyCardObject card = new LoyaltyCardObject();
                              card.setMail(object.getString("mail"));
                              card.setMarque(object.getString("marque"));
                              card.setCode(object.getString("code"));
  
                              cards.add(card);
                          }
                          hideDialog();
                          adapter.notifyDataSetChanged();
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              }, new Response.ErrorListener() {
          @Override
          public void onErrorResponse(VolleyError error) {
              View view = getView();
              LinearLayout ll = (LinearLayout) view.findViewById(R.id.cardlist);
              Log.d("ERROR!!!", error.toString());
              hideDialog();
              Snackbar snackbar = Snackbar  //Si l'utilisateur n'a pas de carte de fidelite, affiche un snackbar qui propose d'ajouter une carte
                      .make(ll, "Aucune carte", Snackbar.LENGTH_LONG)
                      .setAction("Ajouter", new View.OnClickListener() {
                          @Override
                          public void onClick(View view) {
                              builder = new AlertDialog.Builder(getActivity());
                              builder.setTitle("Ajout de carte");
                              builder.setMessage("Comment ajouter ?");
                              builder.setPositiveButton("Scanner", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
                                      dialog.dismiss();
                                      Log.i("Alert", "YES");
                                      Intent intent = new Intent(getActivity(), LoyaltyCardAddWithScannerActivity.class);
                                      startActivity(intent);
                                  }
                              });
                              builder.setNegativeButton("Manuel", new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog, int which) {
                                      dialog.dismiss();
                                      Log.i("Alert", "NO");
                                      startActivity(new Intent(getActivity(), LoyaltyCardAddActivity.class));
                                  }
                              });
                              AlertDialog alertDialog = builder.create();
                              alertDialog.show();
                          }
                      });
              snackbar.show();
          }
      });
      AppController.getInstance().getRequestQueue().add(jsonArrayRequest);
  }
  
  public void showDialog() {
      if (!dialog.isShowing())
          dialog.show();
  }
  
  public void hideDialog() {
      if (dialog.isShowing())
          dialog.hide();
  }
  
  @Override
  public void onDestroyView() {
      super.onDestroyView();
      dialog.hide();
      dialog.dismiss();
  }
  </code></pre>
  
  <p>}</p>