如何打开进度的alertDailog里面呢? [英] how to open ProgressBar inside the alertDailog?

查看:156
本文介绍了如何打开进度的alertDailog里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我版本的Andr​​oid M新人。
我正在faceing一些麻烦
我的方案是 - 当我按一下按钮,打开alertDailog和alertdailog有两个按钮像发送和取消,当我点击发送按钮,我想开一个进度条,因为发送按钮有havy内容,因此需要更多的时间。

I M使用的处理程序,但没有发现任何精确解

读音字使用此code

btn.setOnClickListener(新View.OnClickListener(){
            公共无效的onClick(视图v){

  handler.sendEmptyMessage(0);        }    });
  警报=新的对话框(ProgramDetailActivity.this);        alert.setContentView(R.layout.dialog_email);
        alert.setTitle(输入电子邮件信息);
        alert.setCancelable(真);
        新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话框,
                    INT ID){
                完();
            }
        };
             btnSend =(按钮)alert.findViewById(R.id.btnsend);
         btnBack =(按钮)alert.findViewById(R.id.btncancel);        alert.show();

btnSend.setOnClickListener(新View.OnClickListener(){

  @燮pressWarnings(空)
                         公共无效的onClick(视图v){
                        handler2.sendEmptyMessage(0);

//执行长调度研究
                   progressDialog.dismiss();

  =敬酒Toast.makeText(ProgramDetailActivity.this,邮件已发送成功!

Toast.LENGTH_LONG);
toast.show();

}
}

私人处理器handler2 =新的处理程序(){
        公共无效的handleMessage(消息MSG){
            alert.hide();
            alert.cancel();
            alert.dismiss();

  progressDialog = ProgressDialog.show(v.getContext(),电子邮件发送,请稍候...);
    }
};


解决方案

我也用Progressdialog在Alertdialog.The code的Click事件如下:

  AlertDialog.Builder submitalert =新AlertDialog.Builder(Summary.this);
 submitalert.setTitle(getResources()。的getString(R.string.app_name))
.setMessage(下称数据提交到数据库?)
.setPositiveButton(是,新DialogInterface.OnClickListener(){                @覆盖
                公共无效的onClick(DialogInterface对话,诠释它){
                    // TODO自动生成方法存根
                    update.setTitle(getResources()的getString(R.string.app_name));
                    update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    update.setCancelable(真);
                    update.setMax(100);
                    update.show();
                    主题背景=新主题(新的Runnable(){
                           公共无效的run(){
                               尝试{
                                   //输入code同时显示进度来运行。
                                   //
                                   //这个例子只是要增加进度条:
                                   //所以继续运行,直到进度值达到最大值
                                   而(update.getProgress()&下; = update.getMax()){
                                       //等待每次更新500毫秒之间
                                       视频下载(500);                                       //活跃的更新处理
                                       progressHandler.sendMessage(progressHandler.obtainMessage());
                                   }                               }赶上(java.lang.InterruptedException E){
                                   //如果事情无法做一些聪明
                               }
                           }
                        });                        //启动后台线程
                        background.start();
                        如果(update.getProgress()== 100)
                           {
                               update.dismiss();
                           }
                    }
            })
            .setNegativeButton(否,新DialogInterface.OnClickListener(){
                @覆盖
                公共无效的onClick(DialogInterface对话,诠释它){
                    // TODO自动生成方法存根                }
            })
            。显示();

i m newcomer in android. i am faceing some trouble my Scenarios is -when i click button so open alertDailog and alertdailog have two button like send and cancel,when i click send button, i wanna to open a ProgressBar because send button have havy content, so take more time.

i m using handler but not found any exact solution

i m using this code

btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {

                handler.sendEmptyMessage(0);

        }

    });
  alert = new Dialog(ProgramDetailActivity.this);

        alert.setContentView(R.layout.dialog_email);
        alert.setTitle("                   Enter mail info");
        alert.setCancelable(true);
        new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,
                    int id) {
                finish();
            }
        };
             btnSend = (Button) alert.findViewById(R.id.btnsend);
         btnBack = (Button) alert.findViewById(R.id.btncancel);

        alert.show();

btnSend.setOnClickListener(new View.OnClickListener() {

            @SuppressWarnings("null")
                         public void onClick(View v) {
                        handler2.sendEmptyMessage(0);

// perform long opration progressDialog.dismiss();

                         toast=Toast.makeText(ProgramDetailActivity.this,"Mail has been sent Sucessfully!",

Toast.LENGTH_LONG); toast.show();

} }

private Handler handler2 = new Handler() { public void handleMessage(Message msg) { alert.hide(); alert.cancel(); alert.dismiss();

progressDialog = ProgressDialog.show(v.getContext(),                                "Email Sending", "Please wait...");
    }
};

解决方案

I have also used Progressdialog in click event of Alertdialog.The code is below:

AlertDialog.Builder submitalert = new AlertDialog.Builder(Summary.this);
 submitalert.setTitle(getResources().getString(R.string.app_name))
.setMessage("Submit the data to database?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    update.setTitle(getResources().getString(R.string.app_name));
                    update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                    update.setCancelable(true);
                    update.setMax(100);
                    update.show();


                    Thread background = new Thread (new Runnable() {
                           public void run() {
                               try {
                                   // enter the code to be run while displaying the progressbar.
                                   //
                                   // This example is just going to increment the progress bar:
                                   // So keep running until the progress value reaches maximum value
                                   while (update.getProgress()<= update.getMax()) {
                                       // wait 500ms between each update
                                       Thread.sleep(500);

                                       // active the update handler
                                       progressHandler.sendMessage(progressHandler.obtainMessage());
                                   }

                               } catch (java.lang.InterruptedException e) {
                                   // if something fails do something smart
                               }
                           }
                        });

                        // start the background thread
                        background.start();
                        if(update.getProgress()== 100)
                           {
                               update.dismiss();
                           }
                    }




            })
            .setNegativeButton("No", new DialogInterface.OnClickListener(){
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }
            })
            .show();

这篇关于如何打开进度的alertDailog里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆