如何打开Android的警报对话框 [英] how can open alert dialog box in android

查看:140
本文介绍了如何打开Android的警报对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打开警告对话框后,成功提交的数据。
我使用以下code,但不起作用。

I want to open alert dialog box after successfully submitted data. I am using following code but not work.

     dialog = ProgressDialog.show(TanantDetails.this, "", "Please Wait...", true);
                new Thread(new Runnable() {
                       public void run() {
                String response;

             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences sp=getSharedPreferences("login",MODE_WORLD_READABLE);
            try {
                 Utility utility=new Utility();
                // 

                 new_url=url+mobile_no.getText().toString();
                response = utility.getResponse(utility.urlEncode(new_url));
                dialog.dismiss();
                if (response.equals("Success"))
                {

                     AlertDialog alertbox = new AlertDialog.Builder(getBaseContext())
                        //.setIcon(R.drawable.no)
                        .setTitle("Submit successfully")
                        .setMessage(""Police will verify documents between preferred timing")
                        .setPositiveButton("ok", new DialogInterface.OnClickListener() {

                            // do something when the button is clicked
                            public void onClick(DialogInterface arg0, int arg1) {
                               TanantDetails.this.finish();
                                Intent i=new Intent(getApplicationContext(),MainActivity.class);
                                i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                                startActivity(i);

                            }
                        })
                          .show(); 


                }

            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
                       }
                 }).start();       


        }  

显示敬酒消息响应成功。

toast show the message response success.

我是新到Android

I am new to android

推荐答案

简单的警告对话框

AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Alert")
                   .setTitle("Warning");

AlertDialog alert =builder.create();
                alert.show();

如果您要添加确定,取消按钮,然后添加

If you want to add ok, cancel buttons then add

builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // User clicked OK button
                    }
                   });

builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                           // User clicked cancel button
                       }
                   });

这篇关于如何打开Android的警报对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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