0

我在这里尝试display progressbar when Calling Soap service and dismiss progressbar when response came from service, but progressbar does not appear。它直接提交数据,当我尝试强制应用时,它崩溃了......

我想在soap方法启动后立即显示进度条,并在它结束时关闭...

请告诉我应该怎么做 ???

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);

    Button btnEnter = (Button) findViewById(R.id.btRegister);
    btnEnter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {

            if (Name.equals("")) {
                textValidation.setText("Please Enter Your Name.");
            } else if (Number.equals("")) {
                textValidation.setText("Please Enter Your Contact Number.");
            } else {
                textValidation.setText("");

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

                request = new SoapObject(NAMESPACE, METHOD_NAME);

                name = new PropertyInfo();
                name.setName("Name");
                name.setValue(Name);
                name.setType(String.class);
                request.addProperty(name);

                number = new PropertyInfo();
                number.setName("Number");
                number.setValue(Number);
                number.setType(String.class);
                request.addProperty(number);

                SoapSerializationEnvelope envp = new SoapSerializationEnvelope(
                        SoapEnvelope.VER11);
                envp.dotNet = true;
                envp.setOutputSoapObject(request);
                HttpTransportSE androidHttpTransport = new HttpTransportSE(
                        URL);
                try {
                    androidHttpTransport.call(SOAP_ACTION, envp);
                    SoapPrimitive response = (SoapPrimitive) envp
                            .getResponse();
                    Response = response.toString();

                    if (Response.equals("Success")) {
                        etName.setText("");
                        etEmail.setText("");
                        etNumber.setText("");
                        imageView.setTag("");

                        CookieManager cm = CookieManager.getInstance();
                        cm.setAcceptCookie(true);
                        cm.setCookie("http://192.168.2.9",
                                "MytestbuddyApp=" + Course);
                        CookieSyncManager.getInstance().sync();

                        Intent openStartingPoint = new Intent(
                                "com.MobileWeb.mytestbuddy.Main");
                        startActivity(openStartingPoint);
                    } else {
                        textValidation.setText("Something is Wrong.");
                    }

                } catch (Exception e) {
                    textValidation.setText(e.toString());
                }
                dialog.dismiss();
            }
        }

    });
4

1 回答 1

1

使用 AsyncTask 使其工作...

public class CallWebServiceAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            //here show your progressdialog
               ProgressDialog dialog = ProgressDialog.show(Register.this,
                    "", "Loading. Please wait...", true);
        }

        @Override
        protected void onPostExecute(Void result1) {
            //here dismiss the progressdialog
                     dialog.dismiss();
}
        @Override
        protected Void doInBackground(Void... arg0) {
            //make your servcie request here
        }
}
于 2013-05-09T11:24:50.953 回答