Android 在片段类中显示ProgressDialog

Android 在片段类中显示ProgressDialog,android,android-fragments,progressdialog,Android,Android Fragments,Progressdialog,我试图在片段类中显示进程对话框。以下代码仅在活动类中工作,但不适用于片段。有人能帮我一个忙吗?为什么这个ProgressDialog实现只在活动中起作用,而不是在片段中起作用 private class ProcessUpdateProfile extends AsyncTask<String, String, JSONObject> { private ProgressDialog nDialog; @Override protected

我试图在
片段
类中显示
进程对话框
。以下代码仅在
活动
类中工作,但不适用于
片段
。有人能帮我一个忙吗?为什么这个
ProgressDialog
实现只在
活动中起作用,而不是在
片段中起作用

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();

    }
}
私有类ProcessUpdateProfile扩展
异步任务{
私人住宅;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
nDialog=newprogressDialog(PFragment.this);//这里我得到一个错误:构造函数ProgressDialog(PFragment)未定义
nDialog.setMessage(“加载…”);
nDialog.setTitle(“检查网络”);
nDialog.SetUndeterminate(假);
nDialog.setCancelable(真);
nDialog.show();
}
}

片段中尝试此操作

 nDialog = new ProgressDialog(getActivity()); 

ProgressDialog
take
Context
input,因此在对象创建中使用
getActivity()

ProgressDialog dialog = ProgressDialog.show(getActivity(), "Loading...", "Please wait...", true);