title: Which is the best way to show a loading sign to the fragment when data loading?
body: <p>We use <kbd>viewpager</kbd> fragment in it, we want to show every single page when <kbd>viewpager</kbd> show a fragment and load data , because it saves memory a lot, but we can not show a sign for loading when data loading, we replace a fragment when asynctask's <code>onPreExecute</code> calls and we replace again when calls <code>onPostExecute</code>, but there is some thing wrong, which is the best way to show loading sign when data loading?</p>
  
  <pre><code>public class TestFragment extends Fragment {
      private FragmentManager manager = null;
  
      private class TestTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              // TODO Auto-generated method stub
  
              getFragmentManager().beginTransaction()
                      .replace(R.id.content_container, new LoadingFragment())
                      .commit();
              super.onPreExecute();
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              try {
                  Thread.sleep(2000);
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              getFragmentManager().beginTransaction()
                      .replace(R.id.content_container, new ContentFragment())
                      .commit();
              super.onPostExecute(result);
          }
      }
  
      public TestFragment(FragmentManager supportFragmentManager) {
          this.manager = supportFragmentManager;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          new TestTask().execute();
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          return inflater.inflate(R.layout.empty_page, null);
      }
  
  }
  </code></pre>