0

Save data from edit texts, text views, spinner selections, and checkboxes from multiple activities into an email:

I am already using:

Intent EmailSend = new Intent(android.content.Intent.ACTION_SEND);
    EmailSend.setType("plain/text");
    EmailSend.putExtra(android.content.Intent.EXTRA_TEXT,
      "Pretext"+edittext.getText().toString());

the put string is not working for items not listed in the .java When I use the last line in that i get error saying -edittext cannot resolved-

and how to get data from checkbox & spinner

I will have 80 or so items to compile to this email over 8 activities

SLYtiger
  • 81
  • 1
  • 6

1 Answers1

2

I wrote a snippet to automate it a little:

ViewGroup     root = (ViewGroup) ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
StringBuilder str  = new StringBuilder();

public void extractText(ViewGroup root, StringBuilder str){
    int count = root.getChildCount();
    for(int i = 0; i < count; i++) {
        View v = root.getChildAt(i);

        if(v instanceof Spinner) {
            str.append(i).append(" Spinner: ").append(((Spinner) v).getSelectedItem());
        } else if(v instanceof TextView) {
            str.append(i).append(" TextView: ").append(((TextView) v).getText());
        } else if(v instanceof CheckBox) {
            str.append(i).append(" Checkbox: ").append(((CheckBox) v).isChecked());
        }else if(v instanceof ViewGroup){
            extractText((ViewGroup)v, str);
        }
    }
}
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
  • @dziobas I put this under EXTRA_TEXT, ? – SLYtiger May 16 '11 at 22:18
  • [Here](http://stackoverflow.com/questions/2197741/how-to-send-email-from-my-android-application) example how to send email. – pawelzieba May 16 '11 at 22:28
  • I have the intent code just fine . . . . I am not understanding your answer post please explain – SLYtiger May 16 '11 at 22:44
  • Wow it seems that peoples answers are sometimes way too complicated for the real problem . . . All i had to do was add this to the class: private EditText edittext; and add this to the OnCreate: edittext = (EditText) findViewById(R.id.edittext); now it works like a charm – SLYtiger May 16 '11 at 22:56
  • @dziobas If you dont mind I would still like to understand your first post better . . . where is that used and how does it work – SLYtiger May 16 '11 at 23:02
  • I couldn've believe that you hadn't got instance of edittext :). I thought that the problem is with big quantity of items, therefore I wrote method to automate extracting data from spinners, textviews and checkboxes from root view of activity to string. I hope that will help you. – pawelzieba May 16 '11 at 23:12
  • @dziobas yes thank you if I may ask for additional advice ... I have nothing written for this so assume the stupidity i had before :( but I need to get spinner, edittext and checkbox info from one activity and place it into the same email on the main activity . . . starting from scratch ... how would i do that? – SLYtiger May 16 '11 at 23:31
  • That should help: [Passing data between activities](http://stackoverflow.com/questions/2965109/passing-data-between-activities-in-android) – pawelzieba May 17 '11 at 04:18
  • @dziobas what do i put for the key and value??? getting error saying key and value cannot be resolved to a variable – SLYtiger May 17 '11 at 14:48
  • I don't know what key and what value. – pawelzieba May 17 '11 at 19:55