Show ProgressDialog in Fragment class

Sini Inis picture Sini Inis · Jul 18, 2014 · Viewed 46.7k times · Source

I am trying to show a ProgressDialog within a Fragment class. The following code just works within an Activity class but not for Fragment. Can somebody please help me on this, why this ProgressDialog implementaion just works within an Activity and not for a Fragment?

private class ProcessUpdateProfile extends
        AsyncTask<String, String, JSONObject> {

    private ProgressDialog nDialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        nDialog = new ProgressDialog(PFragment.this); //Here I get an error: The constructor ProgressDialog(PFragment) is undefined
        nDialog.setMessage("Loading..");
        nDialog.setTitle("Checking Network");
        nDialog.setIndeterminate(false);
        nDialog.setCancelable(true);
        nDialog.show();

    }
}

Answer

M D picture M D · Jul 18, 2014

Try this in Fragment

 nDialog = new ProgressDialog(getActivity());