title: How to show progress bar before fragment loading when fragment view loading is part of asynctask?
body: <p>I have a fragment to show a calendar month view with specific images for each date decided by some logic in runtime. As the fragment loading takes some time, I want to show a progress bar. Since the progress bar itself is part of the fragment view, how can i show it before asynctask finishes. The fragment view is created as per the logic placed within asynctask.  </p>
  
  <p>Showing some code snippet for clarity.</p>
  
  <pre><code>public class CalendarMonthViewFragment extends Fragment implements OnCalculateMonthlyCompleted {
  
  @BindView(R.id.progressBar) ProgressBar progressBar;
  
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                           @Nullable Bundle savedInstanceState) {
  
      new CalculateMonthlyDataTask(this, progressBar).execute(); //asynctask that decides the view
      return inflater.inflate(R.layout.calendar_monthview_fragment, container, false);
  
  }
  
    private class CalculateMonthlyDataTask extends AsyncTask&lt;Void, Void, MonthlyDataResult&gt; {
  
      private OnCalculateMonthlyCompleted listener;
      private ProgressBar progressBar;
  
      private CalculateMonthlyDataTask(OnCalculateMonthlyCompleted listener, ProgressBar progressBar) {
          this.listener = listener;
          this.progressBar = progressBar;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          //progressBar.setVisibility(View.VISIBLE);
      }
  
      @Override
      protected void onProgressUpdate(Void... values) {
          super.onProgressUpdate(values);
      }
  
      @Override
      protected void onPostExecute(MonthlyDataResult monthlyDataResult) {
          super.onPostExecute(monthlyDataResult);
          //progressBar.setVisibility(View.GONE);
  
          listener.onTaskCompleted(monthlyDataResult);
      }
  
      @Override
      protected MonthlyDataResult doInBackground(Void... params) {
  
          panchangMonthlyController.calculateMonthlyCalendar();
          return panchangMonthlyController.getMonthlyDataResult();
      }
  
  }
  }
  </code></pre>