title: How do I pass a variable through a FragmentPagerAdapter to a Fragment?
body: <p>I'm an android beginner, trying to learn, and this is my first question, so please excuse me if the question is too simple and please tell me if I'm using the forum incorrectly.</p>
  
  <p>I have a FragmentActivity using a layout that includes a viewpager; the activity creates an instance of MyFragmentPagerAdapter, which creates several instances of MyFragment. All are support.v4 versions.</p>
  
  <p>I'm trying to find a way to pass an integer value (representing a selection the user has made previously, which could actually be a drawable id) to the fragment. I'm using an intent to pass it 
  to this activity and I know I can can use a bundle to pass a value from the FragmentPagerAdapter to the fragment, but I can't find a way to get it from the activity to the FragmentPagerAdapter. I have tried several ways including changing the constructor but couldn't get that to work. </p>
  
  <p>Am I missing something simple? What is the best way to do this?</p>
  
  <h3>Activity</h3>
  
  <pre><code>    public class SecondActivity extends FragmentActivity {
        private MyIntegerAdapter1 mAdapter1;
        private ViewPager mPager1;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.second_layout);
          mAdapter1 = new MyIntegerAdapter1(getSupportFragmentManager());
          mPager1 = (ViewPager) findViewById(R.id.pager1);
          mPager1.setAdapter(mAdapter1);
  </code></pre>
  
  <h3>FragmentPagerAdapter</h3>
  
  <pre><code>    public class MyIntegerAdapter1 extends FragmentPagerAdapter {
      public MyIntegerAdapter1(FragmentManager fm) {
          super(fm);
      }
      @Override
      public Fragment getItem(int position) {
          switch (position) {
          case 0:
              Fragment f1 = new IntegerFragment();
              Bundle args1 = new Bundle();
              args1.putInt("param", R.drawable.image1);
              args1.putInt("number", 1);
              f1.setArguments(args1);
              return f1;
      etc
  </code></pre>
  
  <h3>Fragment</h3>
  
  <pre><code>    public class IntegerFragment extends Fragment {
        private int imageResourceId;
        private int numberSelected;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          //change to avoid orientation crash
          imageResourceId = getArguments().getInt("param");
          numberSelected = getArguments().getInt("number");
  </code></pre>