title: How can I refresh a ListView in a Fragment from the main Activity?
body: <p>I have a <code>MainActivity</code> which contains a tab bar with two fragments: <code>MainFragment</code> and <code>WishlistFragment</code>. They both extend as <code>ListFragment</code>.</p>
  
  <p>When someone touches a menu item from the Option menu, I want the ListView within the Fragment that <em>is showing</em> to refresh its list using its custom adapter called <code>LazyAdapter adapter</code>.</p>
  
  <p>So in here is where I want the refresh to go in my <code>MainActivity</code> code:</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {   
       switch (item.getItemId()) {
          case R.id.menu_edit:
  
                 // find out which fragment is showing here
                 // refresh the fragment's listview here
                 // adapter.notifyDataSetChanged();
  
                 return true;
          }
  }
  </code></pre>
  
  <p>How can I do this? I am not sure how to call forward into the fragment and how to determine which fragment is showing.</p>
  
  <p>Here is how I have my tabs set up in <code>MainActivity</code>:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      actionBar.addTab(actionBar.newTab().setText("Main").setTabListener(this));
      actionBar.addTab(actionBar.newTab().setText("Wishlist").setTabListener(this));
  }
  
  public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
      // When the given tab is selected, show the tab contents in the container
      ListFragment newfragment = null;
  
      switch (tab.getPosition() + 1)
      {
      case 1:
          newfragment = new MainFragment();
          break;
  
      case 2:
          newfragment = new WishlistFragment();           
          break;
      }
  
      getSupportFragmentManager().beginTransaction()
              .replace(R.id.container, newfragment)
              .commit();
  }
  </code></pre>