开发者

Why ProgressDialog doesn't appear?

I have a problem in my android app. I need a progr开发者_如何转开发essdialog when the user click a button. The problem is that this progressdialog doesn't appear and I don't understand where is the problem. Can anyone help me? This is my code:

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();

            }
        }
    }


This is working for me:

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

otherwise use Asyntask (comment of Adil)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜