我不知道的電子郵件發送的一部分,但我可以幫助你做出的消息框喜歡你想要。
如果刪除下面的代碼:
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { // define the 'OK' button
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
然後對話框將顯示,沒有按鍵,如果你添加.setCancelable(false)
它不會被解僱,直到你告訴它,使用alertDialog.cancel();
這裏的一個示例(修改從我的對話中的一個):
AlertDialog.Builder builder = new AlertDialog.Builder(this); // Create the dialog object
builder.setMessage(R.string.dialog_disclaimer_text) // I use a reference to a string resource - it's good practice instead of using hardcoded text
.setIcon(android.R.drawable.ic_dialog_info) // Here I specify an icon to be displayed in the top corner
.setTitle(R.string.dialog_disclaimer_title)
.setCancelable(false) // This one makes the dialog stay until the dismiss is called
.create().show(); // Show the dialog
該代碼將顯示一個對話框,文本,這將在活動調用builder.dismiss();
之前不會消失 - 然後您必須在某種偵聽器中實現該功能,或者在完成發送後進行回調。在對方的回答
更新
來看,這可能是你的代碼應該怎麼樣子(感謝iturki)
private class SendEmailTask extends AsyncTask<Void, Void, Void> {
AlertDialog.Builder alertDialog; // Define the AlertDialog builder object so it can be used/adressed across the entire class
protected void onPreExecute() {
//Show the dialog first
alertDialog = new Builder(context);
alertDialog.setTitle("Sending...")
.setMessage("Please wait while your details and image is being sent to x.");
.setCancelable(false)
.show();
}
protected void doInBackground(Void... params) {
//Send Email Code
Reusable_CodeActivity.send_email(gmailAC, gmpassword, get_all_details(), image_path, this);
}
protected void onPostExecute(Void result) {
//Dismiss the dialog
alertDialog.dismiss();
}
}
你是什麼意思'不working'? – iTurki 2012-08-12 23:50:59
它在警告框出現之前開始發送電子郵件。 – omega 2012-08-12 23:52:47
您是否將電子郵件發送功能置於單獨的線程中? – iTurki 2012-08-12 23:54:41