2016-11-11 29 views
1

所以我創建了一個窗體,我想從窗體使用按鈕發送數據。在activity_main.xml中,我創建了設計,一些文本框和一個按鈕。現在我寫代碼發送數據到一個Gmail?就像,我是新來的android,但我如何從每個文本框中獲取數據?安卓簡單形式從窗體中獲取數據

+1

EditText的文檔可能是一個很好的開始 –

回答

1

對每一個editText嘗試這String name = editTextName.getText().toString();,你可以做任何你想要的String對象。

2

裏面的按鈕onClick()方法,你應該從TextViewEditText獲取文本,你從這樣的

String name=textviewName.getText().toString(); 
0

要郵寄的東西是存在於你的文本字段,你可以使用下面的內容..

使用此代碼,該活動其中的值存在併發送按鈕.. sendEmail是電子郵件發送Btn ID

protected void sendEmail() { 
Log.i("Send email", ""); 
String[] TO = {""}; 
String[] CC = {""}; 
Intent emailIntent = new Intent(Intent.ACTION_SEND); 

emailIntent.setData(Uri.parse("mailto:")); 
emailIntent.setType("text/plain"); 
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); 
emailIntent.putExtra(Intent.EXTRA_CC, CC); 
emailIntent.putExtra(Intent.EXTRA_SUBJECT, " Your Subject"); 
emailIntent.putExtra(Intent.EXTRA_TEXT, " Your Text Here"+((EditText) findViewById(R.id.editTextID)). 
      getText().toString()); 
emailIntent.setType("message/rfc822"); 

try { 
    startActivity(Intent.createChooser(emailIntent, "Send mail...")); 
    finish(); 
} 
catch (android.content.ActivityNotFoundException ex) { 
    Toast.makeText(CurrentActivityName.this, "There is no email client installed.", Toast.LENGTH_SHORT).show(); 
}} 

您可以通過加入+號在EXTRA_TEXT中使用多個TextView值或EditText值。

+0

編輯你的currentActivityName ..在這種情況下是MainActivity – faisal