title: Update Fragment from ViewPager
body: <p>I have an <code>Activity</code> with a <code>ViewPager</code>. I also have a <code>Dialog</code> that will retrieve a list with some items that the user will choose. Now, how can I update the <code>Fragment</code> where the Items are supposed to display as new views attached to this Fragment? </p>
  
  <p>Here is my <code>ViewPager</code>'s adapter:</p>
  
  <pre><code>public static class MyAdapter extends FragmentPagerAdapter {
      public MyAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public int getCount() {
          return 1;
      }
  
      @Override
      public android.support.v4.app.Fragment getItem(int position) {
          switch (position) {
          case 0:
              return new Fragment1();
  
          default:
              return null;
          }
      }
  }
  </code></pre>
  
  <p>Now, here is the <code>Fragment</code>:</p>
  
  <pre><code>public class Fragment1 extends Fragment{
  
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onActivityCreated(savedInstanceState);
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public ViewGroup onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      ViewGroup view = (ViewGroup)inflater.inflate(R.layout.screen1, container, false);
      }
      return view;
  }
  
  }
  </code></pre>
  
  <p>This is the method that I want to use to add Items to my <code>Fragment</code></p>
  
  <pre><code>private void addItem() {
  
      // Instantiate a new "row" view.
  
      final ViewGroup[] newViews = new ViewGroup[selectedItems.length];
  
  
      for(int i = 0; i &lt; selectedItems.length; i++){
          newViews[i] = (ViewGroup) LayoutInflater.from(this).inflate(
                      R.layout.animated_layout_item, mContainerView, false);
  
          // Set the text in each new row.
          ((TextView) newViews[i].findViewById(android.R.id.text1)).setText(selectedItems[i]);
  
          // Because mContainerView has android:animateLayoutChanges set to true,
          // adding this view is automatically animated.
  
              mContainerView.addView(newViews[i], 0);
  
  
          // Set a click listener for the "X" button in the row that will remove the row.
          OnClickListener listener = new MyAddItemListener(newViews[i], mContainerView, this);
          newViews[i].findViewById(R.id.delete_button).setOnClickListener(listener);
  
      }
  
  
  }
  </code></pre>