我不确定我的代码有什么问题,我认为它与dialog.dismiss有关,但也许我错了......我正在尝试设置对话框,当用户按下确定时,电子邮件将发送到某个电子邮件。这是代码:
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.send_dialog);
dialog.setTitle(R.string.send_dialog_title);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
final EditText nameField = (EditText) findViewById(R.id.DialogEditTextName);
String name = nameField.getText().toString();
final EditText commentField = (EditText) findViewById(R.id.DialogEditTextComments);
String comment = commentField.getText().toString();
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("image/*");
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "origameapp@gmail.com" });
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Picture for Facebook page");
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"NAME:"+name+". "+comment);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filepath[position])) );
startActivity(Intent.createChooser(sendIntent, "Send your picture with:"));
}
});
dialog.show();
答案 0 :(得分:3)
您需要致电
final EditText nameField = (EditText) dialog.findViewById(R.id.DialogEditTextName);
final EditText commentField = (EditText) dialog.findViewById(R.id.DialogEditTextComments);
答案 1 :(得分:1)
必须向您显示错误。问题在于findviewbyid,在对话框中搜索视图。请改用这些行。
final EditText nameField = (EditText) dialog.findViewById(R.id.DialogEditTextName);
final EditText commentField = (EditText) dialog.findViewById(R.id.DialogEditTextComments);