2013-05-16 19 views
0

我有一個ListView兩個TextViews爲result.One是結果和其他的描述。我Listview包含10行.The問題是,我怎麼能使用Android的默認郵件撰寫電子郵件的內容?當用戶按下電子郵件按鈕,列表視圖中的內容複製到剪貼板郵件列表視圖內容的電子郵件

+0

是電子郵件按鈕就在您的ListView行作爲另外兩個textViews。 –

+0

沒有電子郵件按鈕是像列表視圖一樣的單獨或超出列表視圖。 – Aaloka

+0

OK,然後首先你必須點擊上獲得根據其對發送按鈕的點擊位置。而它的數據傳遞與數據發送郵件的意圖的ListView。 –

回答

1
String getvalue; 
for(int i =0;i<getListView.getChildCount();i++){ 
LinearLayout layout = getListView.getChildAt(i); 

getvalue = layout.getChildAt(1).getText(); 

}

mailbutton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 

      Intent email = new Intent(Intent.ACTION_SEND); 
      email.putExtra(Intent.EXTRA_EMAIL, new String[]{ to}); 

      email.putExtra(Intent.EXTRA_SUBJECT, subject); 
      email.putExtra(Intent.EXTRA_TEXT, getvalue); 

      //need this to prompts email client only 
      email.setType("message/rfc822"); 

      startActivity(Intent.createChooser(email, "Choose an Email client :")) 
      } 
     }); 
+0

嘿,我需要把所有的結果不是一個值 – Aaloka

+0

檢查它。我編輯了我的答案。 – Riser

1

放在項目點擊聽者以列表視圖,將返回的項目的位置,也就是說,你的ListView的行像下面。

listview.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> arg0, View view, 
        int position, long arg3) { 
       String items= yourarray.getItem(position); 

       //call sendEmail method on click of that send email button. 
      } 
     }) 

;

private void sendEmail(Context context, String[] recipientList, 
       String subject, String body, String title) { 
      Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.setType("plain/text"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, recipientList); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
      emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); 
      emailIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
      emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      try 
      { 
      context.startActivity(Intent.createChooser(emailIntent, title)); 

      }catch(Exception e) 
      { 
       System.out.println(e); 
      } 
     } 
+0

嘿,我該如何複製或傳遞內容?我有10行。 – Aaloka

0

調用此方法的onclick電子郵件與電子郵件地址和作爲主體和主題要添加爲電子郵件作曲家的現場數據發送按鈕。

public void sendEmail(String emaillAddressOfRecipent, String data,String strSubJect) { 
     Intent email = new Intent(Intent.ACTION_SEND); 
     email.putExtra(Intent.EXTRA_EMAIL,new String[] { emaillAddressOfRecipent }); 
     email.setType("message/rfc822"); 
     email.putExtra(Intent.EXTRA_SUBJECT, priority.getSelectedItem() + " : "+ strSubJect); 
     email.putExtra(Intent.EXTRA_TEXT, data); 
     try { 
      startActivity(Intent.createChooser(email, "Send mail...")); 
     } catch (android.content.ActivityNotFoundException ex) { 
      Toast.makeText(this, "There are no email clients installed.",Toast.LENGTH_SHORT).show(); 
     } 
    } 

,其中數據是dataof你的ListView位置