我只有一個屏幕和一個按鈕(稍後我會添加更多內容)。但是現在,我想要做到這一點,當按鈕被點擊時,它會彈出一個對話框,其中有兩個選項。這兩個選項都是電子郵件意向,它只是傳遞給電子郵件客戶端的數據不同。這可能嗎?我是一名新開發人員,這是我的首發項目之一,請耐心等待。提前致謝。對話框中按鈕的不同電子郵件意圖
好了,我發現我的答案(我把這個在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