SITUATION
I have been reading a lot of stuff about this on google but I still can't solve my problem. I have an app that, once you press a button, has to execute a lot of tasks before showing the output. I want to display a progress dialog like this:
Very easy, the circle that is moving on the left and the text "Calculating results..." on the left.
PROBLEM
I have the following code:
public class fragmentMetodoTangenti extends Fragment {
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) { 
  // Inflate the layout for this fragment
  final View view = inflater.inflate(R.layout.fragment_metodo_tangenti, container, false);
  Button button = (Button) view.findViewById(R.id.button1);
  button.setOnClickListener(new View.OnClickListener() {
   @Override
        public void onClick(View v) {
         try {
             loading = new ProgressDialog(view.getContext());
             loading.setCancelable(true);
             loading.setMessage("Calculating results...");
             loading.setProgressStyle(ProgressDialog.STYLE_SPINNER);
             loading.show();
          //other "heavy" code here (a lot of for and while loops)
             loading.dismiss();
         } catch (Exception e) {
          //catching the error
         }
  });
  //return the view
  return view;
 }
}
The code works perfectly because I see the correct output at the end (some numbers and letters). The only problem is that when I click the button I cannot see the Progress Dialog with the spinner inside.
I think that the problem could be on new ProgressDialog(view.getContext()); but I am not sure. I am using the latest version of Android Studio.
How could I solve this?

 
     
     
    