为什么没有出现ProgressDialog?

时间:2011-08-30 09:49:44

标签: android progressdialog

我的Android应用中存在问题。当用户单击按钮时,我需要progressdialog。问题是这个progressdialog没有出现,我不明白问题出在哪里。谁能帮我?这是我的代码:

public void btnSend_onClick(View c) {

         dialogwait = ProgressDialog.show(SendPhoto.this, "",
          "Loading. Please wait...", true); dialogwait.show();

         //dialogwait = ProgressDialog.show(this, "Loading..", "Please wait...", true,        false);
          Handler message = new Handler() {

                @Override
                public void handleMessage(Message msg) {
                    switch (msg.what) {

                    }
                    dialogwait.cancel();

                }
            };

            message.sendEmptyMessageDelayed(0, 3 * 1000);

        surname = eTxtSurname.getText().toString();
        name = eTxtName.getText().toString();
        email1 = eTxtEmail.getText().toString();
        phone1 = eTxtPhone.getText().toString();

        shop_id = Singleton.getInstance().getShop();

        boolean ok = isEmailValid(eTxtEmail.getText().toString());
        System.out.println("ok e" + ok);

        System.out.println("ok e" + surname);
        System.out.println("ok e" + name);
        System.out.println("ok e" + email1);
        System.out.println("ok e" + phone1);

        sendimg.setVisibility(View.INVISIBLE);

        if ((surname.isEmpty()) || (name.isEmpty()) || (email1.isEmpty())
                || (phone1.isEmpty())) {

            Toast.makeText(this, error_complete, Toast.LENGTH_SHORT).show();
            sendimg.setVisibility(View.VISIBLE);
        } else if (ok != true) {
            dialogwait.cancel();
            Toast.makeText(getBaseContext(), email_valid, Toast.LENGTH_SHORT)
                    .show();
            sendimg.setVisibility(View.VISIBLE);
        } else {
            String r = executeMultiPartPost(surname, name, email1, phone1,
                    shop_id);

            if (r.equals("ok")) {

                alertDialog = new AlertDialog.Builder(this).create();
                alertDialog.setTitle(sent_ok);
                alertDialog.setMessage(alertmsg);
                alertDialog.setButton("OK",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                Intent i = new Intent(getBaseContext(),
                                        com.Xperiaproject.Participe.class);
                                startActivity(i);
                                return;
                            }
                        });
                alertDialog.show();

            }
        }
    }

1 个答案:

答案 0 :(得分:1)

这对我有用:

 ProgressDialog loader = ProgressDialog.show(this, "", "Working...", true);
          new Thread(new Runnable(){
              public void run() {
                    //do the work here
                if(loader!=null){
                  loader.dismiss();}}
          }).start();       

否则使用Asynctask(Adil的评论)