Listview内容电子邮件

时间:2013-05-16 06:57:52

标签: android email android-intent android-listview

我有ListView,结果有两个TextViews。其中一个是结果,另一个是描述。我的Listview包含10行。问题是如何使用Android默认邮件编辑器通过电子邮件发送内容。当用户按下电子邮件按钮时,Listview的内容将复制到邮件剪贴板

3 个答案:

答案 0 :(得分:1)

Put on item click listener to 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);
            }   
        }

答案 1 :(得分: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 :"))
            }
        });

答案 2 :(得分:0)

调用此方法点击电子邮件发送按钮,将电子邮件地址和数据作为主体和主题添加为电子邮件作曲家的字段。

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

其中data是listView位置的数据