0

ここで私はしようとしていdisplay progressbar when Calling Soap service and dismiss progressbar when response came from service, but progressbar does not appearます。データを直接送信し、強制適用しようとするとクラッシュします...

ソープメソッドの起動と同時にプログレスバーを表示し、終わったら閉じるようにしたい...

何をすべきか教えてください???

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 に答える