我有一个带有两个TextViews
的ListView
,因为result.One是result,其他是description。我的Listview
包含10行.The问题是,我如何使用安卓默认邮件编辑器通过电子邮件发送内容?当用户按下电子邮件按钮时,Listview的内容将复制到邮件剪贴板
发布于 2013-05-16 15:17:43
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-16 15:03:27
放在项目上,单击listner到listview,这将返回项目的位置,即您的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);
}
}
发布于 2013-05-16 15:09:14
调用此方法onclick email send按钮,将电子邮件地址和数据作为正文和主题,并将其添加为电子邮件编写器的字段。
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职位的数据
https://stackoverflow.com/questions/16580888
复制相似问题