简体   繁体   中英

How to start progress dialog on button click of alert dialog in android?

I want to start progress dialog on click of YES button of Alert Dialog. But when I run it. It gives me a warning of Window already focused, ignoring focus gain of. It sometimes works and sometimes gives warning. And the progress dialog does not starts. Please provide some suggestions

For example -

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    AlertDialog.Builder ab = new AlertDialog.Builder(this);
    ab.setMessage("Choose Yes/No :");
    ab.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            // TODO Auto-generated method stub
            arg0.dismiss();
            ProgressDialog pd = new ProgressDialog(PDActivity.this);
            pd.setMessage("test");
            pd.show();
            pd.setCancelable(true);
        }
    });

    ab.setNegativeButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }
    });
    ab.show();
}

Try like above..

在启动进度对话框之前关闭警报对话框。

单击是按钮时,先关闭警报对话框,然后启动进度对话框。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM