title: Refresh RecyclerView fragment from another fragment's adapter
body: <p>I am making an Android e-commerce app connected to WordPress. In my app I have <em>two Fragments</em>: a <strong>Shop fragment</strong> (with products fetched from the website in it) and <strong>My Wishlist fragment</strong> (with wishlist products in it). I also have <em>two lists</em>: one for the <strong>retrieved products</strong> and another one for the <strong>wishlist products</strong>. The list of the wishlist products contains every product's index inside the retrieved products list so I can get the full details later (image, description, etc...).</p>
  
  <p>The problem I am facing is when adding products to the wishlist, I want to be able to click the wishlist button in the <strong>Shop fragment</strong> and the wishlist products would show in the <strong>My Wishlist fragment</strong>. I searched a lot online and I found out that I should use <code>notifyDataSetChanged</code> but I didn't find any example with how to call it from other Fragments.</p>
  
  <p>If I understand correctly, I should call the <code>WishlistProductAdapter</code> from the <code>ShopProductAdapter</code> but I'm a beginner in Android development so I'm not sure if I can pull this off by myself.</p>
  
  <p>I believe that this code, which is inside <strong>MyWishlist.java</strong> (fragment), can help:</p>
  
  <pre><code>//getting the recyclerview from xml
  RecyclerView recyclerView = (RecyclerView) getView().findViewById(R.id.wishlist_products);
  recyclerView.setHasFixedSize(true);
  recyclerView.setLayoutManager(new StaggeredGridLayoutManager(getResources().getInteger(R.integer.products_column_count), StaggeredGridLayoutManager.VERTICAL));
  
  JSONArray shop_products = //fetched from website, done in MainActivity;
  ArrayList&lt;String&gt; wishlist_products = ["3","0"]; // It contains product of index 0 and product of index 3 inside shop_products
  //initializing the productlist
  List&lt;Product&gt; productList = new ArrayList&lt;&gt;();
  
  for (int i=0; i&lt;wishlist_products.size(); i++) {
      String index = wishlist_products.get(i);
      JSONObject JO = (JSONObject) shop_products.get(Integer.parseInt(index));
  
      productList.add(
              new Product(
                      i,                                            //index
                      Integer.parseInt(JO.get("id").toString()),    //id
                      JO.get("title").toString(),                   //title
                      null,
                      null,
                      JO.get("price").toString(),                   //price
                      JO.get("featured_image_url").toString(),      //image_url
                      null
              )
      );
  }
  //creating recyclerview adapter
  adapter = new WishlistProductAdapter(getActivity().getApplicationContext(), productList);
  
  //setting adapter to recyclerview
  recyclerView.setAdapter(adapter);
  </code></pre>
  
  <h2>EDIT:</h2>
  
  <p>and <strong>Shop.java</strong> is the same except for the for loop (fragment):</p>
  
  <pre><code>for (int i=0; i&lt;shop_products.length(); i++) {
      JSONObject JO = (JSONObject) shop_products.get(i);
  
      productList.add(
          new Product(
              i,
              Integer.parseInt(JO.get("id").toString()),
              JO.get("title").toString(),
              null,
              null,
              JO.get("price").toString(),
              JO.get("featured_image_url").toString(),
              null
          )
      );
  }
  </code></pre>
  
  <h2>EDIT:</h2>
  
  <p>My code with fragments, adapters and MainActivity is here: <a href="https://ufile.io/25z9e" rel="nofollow noreferrer">https://ufile.io/25z9e</a></p>
  
  <p>Any help is greatly appreciated!</p>