title: How to notify an Adapter in a Fragment from Activity?
body: <p>I have a TabLayout in mainActivity with some tabs, tabs are Fragments.<br>
  And on each Fragment I have a ReclerView.<br>
  From the main Activity I want to call <code>notifyDatasetChange()</code> on my Adapter in my Fragment for updating the UI.<br>
  But how to notify it?</p>
  
  <p>myMainActivity:</p>
  
  <pre><code>     final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
  
  
      TabLayout     tabLayout = (TabLayout) findViewById(R.id.tabLayout);
      tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
      tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
  
  
      final PagerAdapter adapter = new PagerAdapter
              (getSupportFragmentManager(), tabLayout.getTabCount());
      viewPager.setAdapter(adapter);
      viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
      tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              viewPager.setCurrentItem(tab.getPosition());
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
  
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
  
          }
      });
  </code></pre>
  
  <p>One of myTabFragment:</p>
  
  <pre><code> @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      RecyclerView v = (RecyclerView) inflater.inflate(R.layout.tab_fragment_1, container, false);
      SetupRecycleView(v);
      return v;
  }
  
  
  void SetupRecycleView(RecyclerView recList) {
      recList.setHasFixedSize(true);
      LinearLayoutManager llm = new LinearLayoutManager(G.context);
      llm.setOrientation(LinearLayoutManager.VERTICAL);
      //recList.setLayoutManager(new GridLayoutManager(G.context, 2));
      recList.setLayoutManager(llm);
      List&lt;StructGhaza&gt; ghazas = StructGhaza.getAllGhaza("2");
      CardAdapter adapter = new CardAdapter(ghazas);
      recList.setAdapter(adapter);
  }
  </code></pre>
  
  <p>The CardAdapter:</p>
  
  <pre><code>public class CardAdapter extends     RecyclerView.Adapter&lt;CardAdapter.GhazaViewHolder&gt; {
  
  private List&lt;StructGhaza&gt; ghazas;
  
  public CardAdapter(List&lt;StructGhaza&gt; ghazaList) {
      this.ghazas = ghazaList;
  }
  
  @Override
  public int getItemCount() {
      return ghazas.size();
  }
  
  @Override
  public void onBindViewHolder(GhazaViewHolder ghazaViewHolder, int position) {
  
      StructGhaza ghaza = ghazas.get(position);
      ghazaViewHolder.vTitle.setText(ghaza.Name);
      //----Load Image
      Glide.with(G.context)
              .load(ghaza.Aks)
              .placeholder(R.drawable.loading_spinner)
              .crossFade()
              .into(ghazaViewHolder.itemImg);
      //---------------
      ghazaViewHolder.Rate.setRating(ghaza.Star);
      ghazaViewHolder.sampleLayout.setHoverView(ghazaViewHolder.hover);
      ghazaViewHolder.sampleLayout.addChildAppearAnimator(ghazaViewHolder.hover, R.id.tvHover, Techniques.FlipInX);
      ghazaViewHolder.sampleLayout.addChildDisappearAnimator(ghazaViewHolder.hover, R.id.tvHover, Techniques.FlipOutX);
  }
  
  @Override
  public GhazaViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      View itemView = LayoutInflater.
              from(viewGroup.getContext()).
              inflate(R.layout.fragment_carditem, viewGroup, false);
  
      return new GhazaViewHolder(itemView);
  }
  
  public static class GhazaViewHolder extends RecyclerView.ViewHolder {
      protected TextView vTitle;
      protected BlurLayout sampleLayout;
      protected View hover;
      protected ImageView itemImg;
      protected RatingBar Rate;
  
      public GhazaViewHolder(View v) {
          super(v);
          sampleLayout = (BlurLayout) v.findViewById(R.id.sample);
          itemImg = (ImageView) v.findViewById(R.id.item_img);
          hover = LayoutInflater.from(G.context).inflate(R.layout.fragment_hover, null);
          vTitle = (TextView) v.findViewById(R.id.titleTv);
          Rate = (RatingBar) v.findViewById(R.id.rating);
      }
  }
  }
  </code></pre>