title: ViewPager unable to load images lazily with Picasso
body: <p>I have a <code>FragmentActivity</code> in the first tab of a <code>TabHost</code>, and the <code>FragmentActivity</code> itself holds a <code>ViewPager</code>. </p>
  
  <p>The <code>ViewPager</code>'s <code>setAdapter()</code> method sets a <code>FragmentPagerAdapter</code> with a set of <code>Fragment</code>s. The goal is to have swipeable images in the first pane of the <code>TabHost</code>.</p>
  
  <p>To test it, I was loading a bunch of images that I had kept locally in the project's <code>drawable</code> directory. <strong>Everything worked beautifully.</strong></p>
  
  <p>After having tested this initial setup, I'm downloading a bunch of image URLs' off a REST web service. I want these images to load lazily in the <code>ViewPager</code>, and I tried calling Picasso's <code>load()</code> method in three places:</p>
  
  <ol>
  <li><p>The <code>onCreateView()</code> method of the <code>ViewPager</code>'s <code>Fragment</code>s (the same place where I was earlier loading images from the local <code>drawable</code> directory).</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) {                
  
      View myFragmentView = inflater.inflate(R.layout.layout_fragment, container, false);
  
      ImageView imageView = (ImageView)getView().findViewById(R.id.fragment_image);
      String url = getArguments().getString(IMAGE_RESOURCE_URL);
      Context context = getActivity();
      Picasso.with(context).load(url).fit().into(imageView);
  
      return myFragmentView;
  }
  </code></pre></li>
  <li><p>The <code>onViewCreated()</code> method of the <code>ViewPager</code>'s <code>Fragment</code>s.</p>
  
  <pre><code>@Override
  public void onViewCreated(View view, Bundle savedInstanceState){
  
      Context context = getActivity();
      String url = getArguments().getString(IMAGE_RESOURCE_URL);
      ImageView imageView = (ImageView)view.findViewById(R.id.fragment_image);
      Picasso.with(context).load(url).fit().into(imageView);      
  
  }        
  </code></pre></li>
  <li><p>The <code>onInstantiateItem()</code> method of the <code>FragmentPagerAdapter</code>.</p>
  
  <pre><code>@Override
  public Object instantiateItem(ViewGroup container, int position) {
  
      View v = inflater.inflate(R.layout.layout_fragment, container, false);
      Context context = Tab1Activity.this;
      String url = getItem(position).getArguments().getString("IMAGE_RESOURCE_URL");
      ImageView imageView = (ImageView)v.findViewById(R.id.fragment_image);
      Picasso.with(context).load(url).fit().into(imageView);
      return v;
  }
  </code></pre></li>
  </ol>
  
  <p>None of these methods worked. I know that its not a problem with Picasso because the other day I tried using Picasso in a <code>ListView</code> and it worked like a charm. What am I doing wrong ?</p>