I am creating an app that has a suggestion box. When the user inputs information into edit texts, the information is retrieved an put into a string value. The string is then put in the text of the email. However, when the email is sent, the text contains no values for the edit texts.
Here is my code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.suggestions);
Spinner spinner = (Spinner) findViewById(R.id.emailArea);
ArrayAdapter<CharSequence> adapter = ArrayAdapter
.createFromResource(this, R.array.email_array,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
Button send = (Button) findViewById(R.id.emailSendButton);
EditText ettext = (EditText) findViewById(R.id.etEmailText);
EditText returnAddress = (EditText) findViewById(R.id.etReturnAddress);
String text = ettext.getText().toString();
String returnAddressText = returnAddress.getText().toString();
emailText =
"\n\nArea in the Guide: " + area
+ "\n\nSuggestion or Comment: " + text +
"\n\nReturn Address: "+ returnAddressText;
send.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent emailIntent = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
address);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Suggestions/Comments: Black Ops 2");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
emailText);
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send Mail"));
finish();
}
});
}
private void showToast() {
Toast.makeText(this, "Thank you. Your message has been sent.",
Toast.LENGTH_SHORT).show();// TODO Auto-generated method stub
}
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
area = areas[pos];
}
public void onNothingSelected(AdapterView parent) {
}
}
}
However, no matter what is entered, I always get blank text and null for the spinner. Any suggestions?
Retrieve the
EditTextvalues inside theonClickListenerand use that.