title: Update data in RecyclerView when scrolling through tabs in ViewPager
body: <p>I have 3 fragments, say A, B, C, a being the centre fragment and also the fragment which shows when the app launches. A have a database where data can be changed from fragment A. Upon scrolling to either B or C, I want the data to be updated and shown in a RecyclerView. Currently I have the update code in the onCreateView() of the fragment, but since android doesn't call onCreateView() for every time the page is changed, the data does not get updated.</p>
  
  <p>I tried writing a function to refresh the lists and put to <code>addOnPageScrolledListener()</code> in the main activity, but that gives a null pointer exception. </p>
  
  <p>How do I get the data to change whenever I scroll to a fragment?</p>
  
  <p>Fragment Code:</p>
  
  <pre><code>public class RecentFragment extends Fragment {
  
  private DBHelper dbHelper;
  private RecyclerView mRecyclerView;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      dbHelper = new DBHelper(getActivity());
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View rootView = inflater.inflate(R.layout.fragment_list, container, false);
      mRecyclerView = (RecyclerView) rootView.findViewById(R.id.event_list_view);
      mRecyclerView.setHasFixedSize(true);
      LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
      linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
      mRecyclerView.setLayoutManager(linearLayoutManager);
      ArrayList&lt;String&gt; arrayList = dbHelper.getData();
      FavouritesListAdapter listAdapter = new FavouritesListAdapter(getActivity(),arrayList);
      mRecyclerView.setAdapter(listAdapter);
      return rootView;
  }
  public void updateList(){
      ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;();
      FavouritesListAdapter listAdapter = new FavouritesListAdapter(getActivity(),arrayList);
      mRecyclerView.setAdapter(listAdapter);
  }
  </code></pre>