SLYtiger
SLYtiger

Reputation: 81

Save data into an email:

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

Upvotes: 0

Views: 282

Answers (1)

pawelzieba
pawelzieba

Reputation: 16082

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);
        }
    }
}

Upvotes: 2

Related Questions