title: Refresh Fragment Views based on Button Click
body: <p>I have 2 fragments (tabs) that share some data. When one changes the data, I'd like to have that reflected on the other tab. I researched this on stackOverflow and I think the relevant answer has to do with a <code>.notifyDataSetChanged()</code> call, but I can't make it work. Here's the relevant code...</p>
  
  <pre><code>public class EnterCourseData extends FragmentActivity implements ActionBar.TabListener {
  
  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  // Tab titles
  private String[] tabs = { "Pars", "Handicaps" };
  private int courseNumber, teeNumber;
  private Tee tee;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_enter_tees);
      // Initilization
      Intent mIntent = getIntent();
      courseNumber = mIntent.getIntExtra("courseNumber",0);
      Course course = Global.getCourse(courseNumber);
      teeNumber = mIntent.getIntExtra("teeNumber",0);
      tee = course.getTee(teeNumber);
  
      viewPager = (ViewPager) findViewById(R.id.pager);
      actionBar = getActionBar();
      mAdapter = new TabsPagerAdapter(getSupportFragmentManager(), courseNumber, teeNumber);
  
      viewPager.setAdapter(mAdapter);
      actionBar.setHomeButtonEnabled(false);
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);        
  
      // Adding Tabs
      for (String tab_name : tabs) {
          actionBar.addTab(actionBar.newTab().setText(tab_name)
                  .setTabListener(this));
      }
      /**
       * on swiping the viewpager make respective tab selected
       * */
      viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  
          @Override
          public void onPageSelected(int position) {
              // on changing the page
              // make respected tab selected
              actionBar.setSelectedNavigationItem(position);
          }
  
          @Override
          public void onPageScrolled(int arg0, float arg1, int arg2) {
          }
  
          @Override
          public void onPageScrollStateChanged(int arg0) {
          }
      });
  }
  </code></pre>
  
  <p>and further down, here is the onClick method that necessitates the refresh...</p>
  
  <pre><code>public void savePars(View view){
      tee.setSlope(Integer.parseInt(((EditText) findViewById(R.id.enter_tee_slope)).getText().toString()));
      tee.setRating(Double.parseDouble(((EditText) findViewById(R.id.enter_tee_rating)).getText().toString()));
      mAdapter.notifyDataSetChanged();
  }
  </code></pre>
  
  <p>Here is the TabsPagerAdapter...</p>
  
  <pre><code>public class TabsPagerAdapter extends FragmentPagerAdapter {
  int courseNumber, teeNumber;
  
  public TabsPagerAdapter(FragmentManager fm, int courseNumber, int teeNumber) {
      super(fm);
      this.courseNumber = courseNumber;
      this.teeNumber = teeNumber;
  }
  
  @Override
  public Fragment getItem(int index) {
  
      switch (index) {
      case 0:
          // Par Entry activity
          Fragment parFragment = new ParFragment();
          Bundle args = new Bundle();
          args.putInt(ParFragment.ARG_COURSE_NUMBER, courseNumber);
          args.putInt(ParFragment.ARG_TEE_NUMBER, teeNumber);
          parFragment.setArguments(args);
          return parFragment;
      case 1:
          // Handicap Entry fragment activity
          Fragment hcpFragment = new HandicapFragment();
          args = new Bundle();
          args.putInt(HandicapFragment.ARG_COURSE_NUMBER, courseNumber);
          args.putInt(HandicapFragment.ARG_TEE_NUMBER, teeNumber);
          hcpFragment.setArguments(args);
          return hcpFragment;
      }
  
      return null;
  }
  
  @Override
  public int getCount() {
      // get item count - equal to number of tabs
      return 2;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here is one Fragment...</p>
  
  <pre><code>public class ParFragment extends Fragment {
      public static final String ARG_COURSE_NUMBER = "courseNumber", ARG_TEE_NUMBER = "teeNumber";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_par, container, false);
          Bundle args = getArguments();
          Course course = Global.getCourse(args.getInt(ARG_COURSE_NUMBER));
          ((TextView) rootView.findViewById(R.id.display_course_name)).setText(course.getName());
          Tee tee = course.getTee(args.getInt(ARG_TEE_NUMBER));
          ((TextView) rootView.findViewById(R.id.display_tee_name)).setText(tee.getTeeName());
          ((TextView) rootView.findViewById(R.id.enter_tee_slope)).setText(Integer.toString(tee.getSlope()));
          ((TextView) rootView.findViewById(R.id.enter_tee_rating)).setText(Double.toString(tee.getRating()));
  
          return rootView;
      }
  }
  </code></pre>
  
  <p>And here is the other...</p>
  
  <pre><code>public class HandicapFragment extends Fragment {
      public static final String ARG_COURSE_NUMBER = "courseNumber", ARG_TEE_NUMBER = "teeNumber";
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_handicap, container, false);
          Bundle args = getArguments();
          Course course = Global.getCourse(args.getInt(ARG_COURSE_NUMBER));
          ((TextView) rootView.findViewById(R.id.display_course_name)).setText(course.getName());
          Tee tee = course.getTee(args.getInt(ARG_TEE_NUMBER));
          ((TextView) rootView.findViewById(R.id.display_tee_name)).setText(tee.getTeeName());
          ((TextView) rootView.findViewById(R.id.enter_tee_slope)).setText(Integer.toString(tee.getSlope()));
          ((TextView) rootView.findViewById(R.id.enter_tee_rating)).setText(Double.toString(tee.getRating()));
  
          return rootView;
      }
  
  }
  </code></pre>
  
  <p>When the button is clicked, I want to save the values and I want these values to show up on the other fragment.</p>
  
  <p>Help a noob out.</p>
  
  <p>Thanks</p>