【问题标题】:Show ProgressDialog in Fragment class在 Fragment 类中显示 ProgressDialog
【发布时间】:2014-09-09 14:21:29
【问题描述】:

我试图在 Fragment 类中显示 ProgressDialog。以下代码仅适用于 Activity 类,但不适用于 Fragment。有人可以帮我解决这个问题吗,为什么这个 ProgressDialog 实现只适用于 Activity 而不适用于 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();

    }
}

【问题讨论】:

    标签: android android-fragments progressdialog


    【解决方案1】:

    Fragment试试这个

     nDialog = new ProgressDialog(getActivity()); 
    

    【讨论】:

      【解决方案2】:

      ProgressDialog 接受Context 输入,因此在对象创建中使用getActivity()

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-26
        • 2013-10-11
        • 1970-01-01
        • 2012-08-13
        • 1970-01-01
        相关资源
        最近更新 更多