0

不得不问这个问题我感到很愚蠢,但我找不到如何从多个 EditText 视图中获取 UI 信息并将其放置在电子邮件正文中。仅供参考,我的意图是,我只想填充消息正文。

    Intent buildingfireemail = new Intent(android.content.Intent.ACTION_SEND);
            buildingfireemail.setType("plain/text");///.setType("message/rfc822")
            buildingfireemail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"to@email.com"});
            buildingfireemail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
            buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, "Text"
    //////////////I need to add data from 80+ views into here.
    );try {
                startActivity(Intent.createChooser(buildingfireemail, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(BuildingFireActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }
4

2 回答 2

3

试试这个 :

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , editText.getText().toString());
try 
{
     startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
}
于 2012-05-07T04:37:44.967 回答
1

创建一个从所有文本编辑中返回整个字符串的函数。例如:

private String getText() {
    String text = "";

    text += mEditText1.getText().toString() + "\n";
    text += mEditText2.getText().toString() + "\n";

    return text;
}

像这样使用:

buildingfireemail.putExtra(android.content.Intent.EXTRA_TEXT, getText());

类的初始化成员变量:

private EditText mEditText1;

在 setContentView 之后将所有编辑文本带到 onCreate 中的成员变量中:

mEditText1 = (EditText) findViewById(R.layout.editText1);
于 2012-05-07T04:36:36.780 回答