Android 可绘制图形的警报对话框

Android 可绘制图形的警报对话框,android,android-alertdialog,android-menu,Android,Android Alertdialog,Android Menu,我已经为提交按钮选择了一个选项项(菜单项) 在 switch(item.getItemId()){ case R.id.submit: 我想要一个对话框。我该怎么做呢。此提交是res>drawable文件夹中图像的id。 那么,我如何才能将警报对话框添加到该对话框中 总结:我想要确认单击的提交按钮。如果是,我想调用submitDefects()功能。提交不是图像的资源id,而是菜单项的资源id。 public boolean onOptionsItemSelected (MenuItem it

我已经为提交按钮选择了一个选项项(菜单项)

switch(item.getItemId()){
case R.id.submit:
我想要一个对话框。我该怎么做呢。此提交是res>drawable文件夹中图像的id。 那么,我如何才能将警报对话框添加到该对话框中

总结:我想要确认单击的提交按钮。如果是,我想调用
submitDefects()功能。

提交不是图像的资源id,而是菜单项的资源id。
public boolean onOptionsItemSelected (MenuItem item)
 {
 switch(item.getItemId()){
 case R.id.submit:
  AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);

    // Setting Dialog Title
    alertDialog.setTitle("TITLE");

    // Setting Dialog Message
    alertDialog.setMessage("Are you sure you want delete this?");

    // Setting Icon to Dialog
    alertDialog.setIcon(R.drawable.delete);

    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,int which) {

        // Write your code here to invoke YES event
        Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
                     submitDefects();
        }
    });

    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        // Write your code here to invoke NO event
        Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
        dialog.cancel();
        }
    });

    // Showing Alert Message
    alertDialog.show();
            return true;
        }
    }