title: Android: Communication between fragments in a view pager
body: <p>Just for reference I am been trying to follow the answer to this question </p>
  
  <p><a href="https://stackoverflow.com/questions/13700798/basic-communication-between-two-fragments">Basic Communication between two fragments</a> </p>
  
  <p>I have 2 <code>Fragments</code> within a <code>ViewPager</code> <code>Adapter</code> along with an <code>Actionbar</code>.</p>
  
  <p>What I have is one fragment produces some data which can (if chosen) inserted to an SQLite table. 
  The second <code>Fragment</code> simply displays all data in the table, however I am trying to make some communication that as soon as <code>Fragment</code> 1 inserts data into the <code>SQLite</code> table. <code>Fragment</code> 2 is called to refresh its select query (as in do the query again) to automatically show the latest data. At the moment this is manually done with a button which I feel is not great. </p>
  
  <p>This is my <code>interface</code> in <code>Fragment</code> 1</p>
  
  <pre><code>onNumbersSavedListener mCallback;
  
  public interface onNumbersSavedListener
  {
      public void RequestQueryRefresh();
  }
  
  
  @Override
  public void onAttach(Activity activity) {
      // TODO Auto-generated method stub
      super.onAttach(activity);
  
      try
      {
          mCallback = (onNumbersSavedListener) activity;
      }
      catch(ClassCastException e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This is the main <code>Activity</code> which contains the <code>ViewPager</code> and implements the <code>interface</code></p>
  
  <pre><code>public class MainActivity extends FragmentActivity implements TabListener, GenerateFragment.onNumbersSavedListener
  </code></pre>
  
  <p>This is the main problem I am having which I do not have IDs for the fragments which answer referred in the link stated above does so. </p>
  
  <pre><code>@Override
  public void RequestQueryRefresh() {
      // TODO Auto-generated method stub
  
  }
  </code></pre>
  
  <p>TLDR: I am just looking for an easy and clean way for as soon as <code>Fragment</code> 1 saves into DB, fragment 2 updates its list view by re-running its query. </p>