0

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

4

3 回答 3

1

将项目单击列表器放入列表视图,它将返回项目的位置,即您的列表视图行,如下所示。

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);
            }   
        }
于 2013-05-16T07:03:26.603 回答
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 :"))
            }
        });
于 2013-05-16T07:17:42.780 回答
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 位置的数据

于 2013-05-16T07:09:14.100 回答