我只有一个屏幕和一个按钮(稍后我会添加更多内容)。但是现在,我想要做到这一点,当按钮被点击时,它会弹出一个对话框,其中有两个选项。这两个选项都是电子邮件意向,它只是传递给电子邮件客户端的数据不同。这可能吗?我是一名新开发人员,这是我的首发项目之一,请耐心等待。提前致谢。对话框中按钮的不同电子邮件意图
好了,我发现我的答案(我把这个在onclick()方法):
AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
// Setting Dialog Title
alertDialog.setTitle("Save File...");
// Setting Dialog Message
alertDialog.setMessage("Do you want to save this file?");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.save);
// Person presses first option (first email)
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// User pressed YES button. Write Logic Here
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] { "[email protected]" });
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
});
// Person presses second option (second email)
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[] { "[email protected]" });
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
});
// Put a "cancel" button
alertDialog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// User pressed Cancel button. Write Logic Here
Toast.makeText(getApplicationContext(), "You clicked on Cancel",
Toast.LENGTH_SHORT).show();
}
});
// Show the dialog
alertDialog.show();
是的,有可能。 – Nermeen 2013-03-27 07:55:51