ViewPager access inflated view items
<p>I'm trying to implement ViewPager to combine two view within one activity, in which I'm facing NullPointerException when I'm trying to access items using findViewById in inflated views, my custom page adapter is as follows,</p>

<pre><code>public class CustomPagerAdapter extends PagerAdapter {

  @Override
  public int getCount() {

     return 2;
  }

  @Override
  public boolean isViewFromObject(View view, Object object) {

     return view == ((View) object);
  }

  @Override
  public void destroyItem(View view, int value, Object object) {

     ((ViewPager) view).removeView((View) object);
  }

  @Override
  public Parcelable saveState() {

     return null;
  }

  @Override
  public Object instantiateItem(View collection, int position) {

     LayoutInflater layoutInflater = (LayoutInflater) collection.getContext()
           .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

     int resultId = 0;         
     switch (position) {

        case 1:
           resultId = R.layout.layout2;
           break;

        case 0:
        default:
           resultId = R.layout.layout1;
           break;
     }
     View view = layoutInflater.inflate(resultId, null);
     ((ViewPager) collection).addView(view, 0);

     return view;
  }
</code></pre>

<p>}</p>

<p>And my activity is as follows, in which I'm trying to access button which is inside layout1 which throws null value.</p>

<pre><code>   public class PageSwiperActivity extends Activity {

   @Override
   public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      setContentView(R.layout.viewpagerlayout);

      Button myButton=(Button) findViewById(R.id.myButton);
   }
}
</code></pre>

<p>My viewpagerlayout.xml contains only,</p>

<pre><code>&lt;android.support.v4.view.ViewPager
    android:id="@+id/viewPagerLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" /&gt;
</code></pre>

<p>and my layout1.xml contains one button. Give me some guidance.</p>

<p>Thanks.</p>
