-1

i'm not sure what is wrong with my code, i'm thinking it's relate to dialog.dismiss, but maybe i'm wrong... i'm trying to set a dialog and when the user press ok, an email will be sent to some email. here's the code:

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();
arvivlx2
  • 139
  • 1
  • 10

2 Answers2

3

You need to call

 final EditText nameField = (EditText) dialog.findViewById(R.id.DialogEditTextName); 
 final EditText commentField = (EditText) dialog.findViewById(R.id.DialogEditTextComments);  
Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29
1

It must be showing you error. issue is with findviewbyid, search for the views in your dialog. use these lines instead.

final EditText nameField = (EditText) dialog.findViewById(R.id.DialogEditTextName); 
final EditText commentField = (EditText) dialog.findViewById(R.id.DialogEditTextComments);
rachit
  • 1,981
  • 15
  • 23