进度对话框未显示

时间:2012-07-03 18:19:34

标签: android

public Context ctx;
 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.ctx = this;
            //another code......)

        send = (Button)findViewById(R.id.wyslij_zapytanie_ofertowe);
        send.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                ProgressDialog dialog = ProgressDialog.show(ctx, "Loading", "Please wait...", true);
                try {   
                    GMailSender sender = new GMailSender("dasdda@gmail.com", "ddx");
                    sender.sendMail("This is Subject",   
                            "This is Body",   
                            "staxxxowe@gmail.com",   
                            "xxxyk@gmail.com");   
                  dialog.dismiss();
                } catch (Exception e) {   
                    Log.e("SendMail", e.getMessage(), e);
                    dialog.dismiss();
                } 
            }
        });

我也尝试将ctx放入ClassName.class并且也不起作用。任何人都知道如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

您的问题很可能是您在致电dialog.dismiss();后立即致电dialog.show(),这可能导致此“未显示”效果。

dialog.setButton("Cancel", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int which) {
      dialog.dismiss();
   }
});

答案 1 :(得分:0)

它可能在创建之前就被解雇了,因为只有几行后你才会调用dialog.dismiss()