如何关闭片段中的进度对话框?

时间:2018-01-20 07:19:44

标签: android android-fragments progressdialog

我在解雇进度对话框时遇到了问题。我的问题是,当我从片段C按下时,进程对话框函数被调用两次并被解雇两次。我再次回到相同的片段C并按回到片段A,同样的进度对话框被调用两次,但现在只有一个对话框被解除。怎么解决这个问题。该过程在api集成中完成。

从片段C移回片段A的代码

  Fragment_Money_Transfer_Mobile ldf = new  Fragment_Money_Transfer_Mobile();
                        Bundle args = new Bundle();
                        args.putString("number",mobNumber);

                        getFragmentManager().beginTransaction().add(R.id.fragment_container, ldf).commit();

                        Fragment_Money_Registration_Form fragment = new   Fragment_Money_Registration_Form();
                        android.support.v4.app.FragmentTransaction fragmentTransaction =
                                getFragmentManager().beginTransaction();
                        fragment.setArguments(args);
                        fragmentTransaction.replace(R.id.fragment_container, fragment);
                        fragmentTransaction.addToBackStack(  Fragment_Money_Transfer_Mobile.class.getSimpleName() );
                        fragmentTransaction.commit();

显示和取消进度对话框的代码

  public void showProgress() {
    pDialog = null;
    if (pDialog == null) {
        pDialog = new ProgressDialog(getActivity());
        pDialog.setMessage("Processing...");
        pDialog.setCancelable(true);
        pDialog.show();
        count = 1;
    }

}
public void dismissDialog() {
    if (pDialog != null && pDialog.isShowing()){
        pDialog.dismiss();
        pDialog = null;
    }
}

我在全球范围内宣布了进度对话框。

api集成的代码

public void getData(){
    showProgress();

        Ion.with(this)
                .load(HelperClass.SERVER_ID + HelperClass.postApis+"/mtvaliatemobileno")
                .setTimeout(HelperClass.timeOut)
                . setHeader(HelperClass.authName,authToken)
                .setHeader(HelperClass.contentName,HelperClass.contentValue)
                .setHeader(HelperClass.secretKeyName,newEncryptedSecretNumber)
                .setHeader(HelperClass.apiKeyName,encryptedDeviceId)
                .setJsonObjectBody(json)
                .asJsonObject()
                .withResponse()
                .setCallback(new FutureCallback<Response<JsonObject>>() {
                    @Override
                    public void onCompleted(Exception e, Response<JsonObject> result) {
                        dismissDialog();

                        if (e != null) {
                            e.printStackTrace();
                            Toast.makeText(getActivity(), "Connection Failed", Toast.LENGTH_SHORT).show();

                        } else {
                            if (result != null) {

                                try{
                                    Boolean responceMessage = result.getResult().get("res").getAsBoolean();

                                    JsonObject jsonObject1 = result.getResult().get("CardDetail").getAsJsonObject();
}
}                       
}

请帮助我解决这个问题。

0 个答案:

没有答案
相关问题