Note that there are some explanatory texts on larger screens.

plurals
  1. POCapture user input and send them directly to an email address using button
    text
    copied!<p>I am currently working on an Android application which has an order form. I would like to know how I can allow the application to capture what the user has input and send the input directly to an email using button, without bringing the user to the email app page. I know my .java class has errors, however, I am trying out... Below is my xml (layout) file and my .java class file. Please help me... Thanks!! </p> <p>Here is my .xml file (layout) </p> <pre><code>&lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"&gt; &lt;TextView android:id="@+id/txtname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Name: " /&gt; &lt;EditText android:id="@+id/editname" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txtname" android:hint="Your name please" /&gt; &lt;TextView android:id="@+id/txtemail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editname" android:text="Email Address: " /&gt; &lt;EditText android:id="@+id/editemail" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txtemail" android:hint="Enter email address here" /&gt; &lt;TextView android:id="@+id/txtnum" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editemail" android:text="Contact Number: " /&gt; &lt;EditText android:id="@+id/editnum" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txtnum" android:hint="Enter contact number here" /&gt; &lt;TextView android:id="@+id/txtadd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editnum" android:text="Mailing Address: " /&gt; &lt;EditText android:id="@+id/editadd" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txtadd" android:hint="Enter mailing address here" /&gt; &lt;TextView android:id="@+id/txtitems" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editadd" android:text="Item(s): " /&gt; &lt;EditText android:id="@+id/edititems" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/txtadd" android:hint="Enter item(s) here" /&gt; &lt;Button android:id="@+id/btn_submit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/edititems" android:text="Submit form" /&gt; &lt;/TableLayout&gt; </code></pre> <p> </p> <p>Here is my .java class codes</p> <pre><code>public class OrderFormActivity extends Activity implements OnClickListener{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.orderform); Button btnsubmit = (Button)findViewById(R.id.btn_submit); btnsubmit.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if (v == this.findViewById(R.id.btn_submit)) { EditText name = (EditText)findViewById(R.id.editname); String strname = name.getText().toString(); EditText email = (EditText)findViewById(R.id.editemail); String stremail = email.getText().toString(); EditText num = (EditText)findViewById(R.id.editnum); String strnum = num.getText().toString(); EditText add = (EditText)findViewById(R.id.editadd); String stradd = add.getText().toString(); EditText items = (EditText)findViewById(R.id.edititems); String stritems = items.getText().toString(); showOrder(strname, stremail, strnum, stradd,stritems); } } private void showOrder (String strname, String stremail, String strnum, String stradd, String stritems) { String result = strname + stremail + strnum + stradd + stritems; //Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); String emailAddress = "kwok.winona@gmail.com"; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("plain/text"); intent.putExtra(Intent.EXTRA_EMAIL, emailAddress); intent.putExtra(Intent.EXTRA_TEXT, result); } </code></pre> <p>}</p> <p>Thanks all again in advance!!! :D </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload