2012-05-07 41 views
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[]{"[email protected]"}); 
      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(); 
      } 
+0

我是新來的,學習隨我去FYI。 – KyleM

+0

看來你的代碼是正確的。你用這個代碼得到什麼? –

回答

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; 

採取一切編輯文本,以成員變量的onCreate的setContentView後:

mEditText1 = (EditText) findViewById(R.layout.editText1); 
+0

我的意思是我真的很新。 。 。我不確定那裏是哪裏,哪個部分替換了我的頭銜? – KyleM

2

試試s:

Intent i = new Intent(Intent.ACTION_SEND); 
i.setType("text/plain"); 
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
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(); 
} 
相關問題