I am trying to have more than one Edittext fields to send via a intent to email.
the code will make more sense of what i am trying to accomplish,
public class EmailSupport extends Activity {
Button buttonSend;
String textTo;
EditText textSubject;
EditText nametext;
EditText emailtext;
EditText phonetext;
EditText topictext;
EditText detailstext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email_form_to_support);
public void onClick(View v) {
String[] recipients = new String[]{"email@email.com", "email@email.com",};
String subject = textSubject.getText().toString();
String name = nametext.getText().toString();
String emails = emailtext.getText().toString();
String phone = phonetext.getText().toString();
String topic = topictext.getText().toString();
String details = detailstext.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(android.content.Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.putExtra(Intent.EXTRA_TEXT, name);
email.putExtra(Intent.EXTRA_TEXT, emails);
email.putExtra(Intent.EXTRA_TEXT, phone);
email.putExtra(Intent.EXTRA_TEXT, topic);
email.putExtra(Intent.EXTRA_TEXT, details);
I need to know how to incorporate all the edittext inputs as see in the layout file below to basic add to the message text in the email. my topic edittext is my subject for the email and i want to hardline a email address to send it too by default.
email_form_to_support.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/name" />
<EditText
android:id="@+id/nametext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email" />
<EditText
android:id="@+id/emailtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:minLines="1"
android:scrollbars="vertical" />
<TextView
android:id="@+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/phone" />
<EditText
android:id="@+id/phonetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:maxLines="8"
android:minLines="1"
android:scrollbars="vertical" />
<TextView
android:id="@+id/topic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/topic" />
<EditText
android:id="@+id/topictext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:maxLines="3"
android:minLines="1"
android:scrollbars="vertical" />
<TextView
android:id="@+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/details" />
<EditText
android:id="@+id/detailstext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:maxLines="8"
android:minLines="1"
android:scrollbars="vertical" />
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/submit" />
</LinearLayout>
Any help would be appreciate. I feel like im just missing something simple however i may be wrong. So far with this method of source i am getting errors on the String message = xxxtext.getText().toString(); because i have it several time. I dont know what to put for each one.
Per Pavel Dudka recommended I change my Source to This
public class EmailSupport extends Activity {
Button buttonSend;
String textTo;
EditText textSubject;
EditText nametext;
EditText emailtext;
EditText phonetext;
EditText topictext;
EditText detailstext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email_form_to_support);
buttonSend = (Button) findViewById(R.id.submit);
textTo = (String) getString(R.string.to);
textSubject = (EditText) findViewById(R.id.topictext);
nametext = (EditText) findViewById(R.id.nametext);
emailtext = (EditText) findViewById(R.id.emailtext);
phonetext = (EditText) findViewById(R.id.phonetext);
topictext = (EditText) findViewById(R.id.topictext);
detailstext = (EditText) findViewById(R.id.detailstext);
buttonSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
StringBuilder emailBodyBuilder = new StringBuilder();
emailBodyBuilder.append(textSubject.getText().toString());
emailBodyBuilder.append("\n");
emailBodyBuilder.append(nametext.getText().toString());
emailBodyBuilder.append("\n");
emailBodyBuilder.append(emailtext.getText().toString());
emailBodyBuilder.append("\n");
emailBodyBuilder.append(topictext.getText().toString());
emailBodyBuilder.append("\n");
emailBodyBuilder.append(phonetext.getText().toString());
emailBodyBuilder.append("\n");
emailBodyBuilder.append(detailstext.getText().toString());
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email1@domen.com", "email2@domen.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, textSubject.getText().toString());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailBodyBuilder.toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
}
}
I’m not certain what you are trying to accomplish but change this:
to this:
Here each EditText is stored in it’s own String, for you to use as you please.
Addition from comments
Simply combine the Strings, this is one easy way:
Where a “\n” is a line break like using Enter. You can setup a more interesting format between the fields, perhaps:
But that is up to you.