title: Using ViewPager and AsyncTask together
body: <p>If I start an <code>AsyncTask</code> within the <code>getItem()</code> function of a <code>ViewPager</code> Adapter, passing the Fragment <code>getItem()</code> later returns to the <code>AsyncTask</code> as a parameter (see below).</p>
  
  <p>Can I then call a method belonging to the Fragment (<code>setString()</code>) in the <code>AsyncTask</code>s <code>onPostExecute</code> and will this still affect the Fragment shown even though it has most likely already been returned by the <code>ViewPager</code>s <code>getItem()</code> before the <code>AsyncTask</code> completes?</p>
  
  <pre><code>private class SlidePagerAdapter extends FragmentStatePagerAdapter {
          public Fragment getItem(int position) {
  
                  MyListFragment listfrag = new MyListFragment(); //Create the fragment
                  new AsyncTaskLoader(listfrag).execute(); //Start the AsyncTask, passing the Fragment
                  return listfrag;
          }
  
  }
  </code></pre>
  
  <p>And my AsyncTask in the same Activity class as the Adapter Above</p>
  
  <pre><code>protected class AsyncTaskLoader extends AsyncTask&lt;String, Void, String&gt; {
      private MyListFragment f;
      AsyncTaskLoader(MyListFragment f){
          this.f=f;
      }
      protected String doInBackground(String... arg0) {....code...} //This takes a while..
      protected void onPostExecute(String result) {
          f.setString("hello world"); // Will this still update the fragment created in getItem()?
      }
  }
  </code></pre>
  
  <p>And the fragment class</p>
  
  <pre><code>    public class MyListFragment extends ListFragment {
          ....code....
          public setString(String text){
              TextView str = (TextView) findViewById(R.id.text);
              str.setText(text);
          }
      }
  </code></pre>
  
  <p>Apologies if the way I explained it is hard to understand, the code should explain it better</p>
  
  <p>Basically I guess the question is, even though the <code>ViewPager</code>s <code>getItem()</code> has returned the fragment, can I still change the fragments properties after in the parent Activity?</p>