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!!
Here is my .xml file (layout)
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TextView
android:id="@+id/txtname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
/>
<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"
/>
<TextView
android:id="@+id/txtemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editname"
android:text="Email Address: "
/>
<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"
/>
<TextView
android:id="@+id/txtnum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editemail"
android:text="Contact Number: "
/>
<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"
/>
<TextView
android:id="@+id/txtadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editnum"
android:text="Mailing Address: "
/>
<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"
/>
<TextView
android:id="@+id/txtitems"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editadd"
android:text="Item(s): "
/>
<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"
/>
<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"
/>
</TableLayout>
Here is my .java class codes
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);
}
}
Thanks all again in advance!!! :D