Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实现Android对话框?_Android_Dialog - Fatal编程技术网

如何实现Android对话框?

如何实现Android对话框?,android,dialog,Android,Dialog,如何在我的android项目中实现对话框?您是在寻找简单的AlertDialog还是Dialogbox 警报对话框示例: AlertDialog.Builder alertDialog = new AlertDialog.Builder(Borc.this); // Setting Dialog Title alertDialog.setTitle("Eraser"); // Set

如何在我的android项目中实现对话框?

您是在寻找简单的AlertDialog还是Dialogbox

警报对话框示例:

         AlertDialog.Builder alertDialog = new AlertDialog.Builder(Borc.this);
                // Setting Dialog Title
                alertDialog.setTitle("Eraser");
                // Setting Dialog Message
                alertDialog.setMessage("Are you sure?");
                // Setting Icon to Dialog
                alertDialog.setIcon(R.drawable.remove);
                // Setting Positive "Yes" Button
                alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dataBase.borclar.delete(String.valueOf(tableHelper.getSelectedRowId()));
                    }
                });
                // Setting Negative "NO" Button
                alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
                // Showing Alert Message
                alertDialog.show();

在任何需要显示对话框的地方使用此代码

AlertDialog.Builder builder =new AlertDialog.Builder(Dialogs.this);
builder.setIcon(R.drawable.save1);
builder.setTitle("Save Your Work");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

 @Override
 public void onClick(DialogInterface dialog, int which) {
                // do something.......
  }
 });
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

 @Override
 public void onClick(DialogInterface dialog, int which) {
                // do something.......
  }
 });
AlertDialog alert = builder.create();
alert.show();

我认为使用android对话框的最佳方式是阅读文档:。它们描述了各种类型的对话框以及如何在应用程序中实现它们


如果您有特定问题,请向我们展示您的代码并提出正确的问题。

您有什么问题?你能详细说明一下吗?非常感谢………..:)您可以下载图像以添加到对话框..public void onClick(View v){DB.open();Cursor c=DB.getContact(“1”);if(c.moveToFirst()){do{Display(c);}while(c.moveToNext());}DB.close();String checkPass=pass.getText().toString();if(checkPass.equals(getpass)){startActivity(newintent(Welcome.this,Main.class));}else{Toast.makeText(getBaseContext(),“错误密码”,Toast.LENGTH_LONG).show()}