I have a ListView
with two TextViews
as result.One is result and other is description. My Listview
contains 10 rows .The question is that how can I E-mail the content using android default mail composer.? When user press the email button, the contents of the Listview copy to the mail clipboard
Asked
Active
Viewed 1,775 times
0

Aaloka
- 115
- 2
- 11
-
is the email button is on your listView row as other two textViews. – Rishabh Bhardwaj May 16 '13 at 07:00
-
No the email button is separate or outof listview like under the listview. – Aaloka May 16 '13 at 07:01
-
ok then firstly you have to click on listView on get its data according to its position .And on click of Send button pass the intent of send mail with that data. – Rishabh Bhardwaj May 16 '13 at 07:04
3 Answers
1
Put On item click listner to listview that will return position of items that is your row of listview like below.
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);
}
}

user1621629
- 765
- 7
- 19
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 :"))
}
});

Sagar Maiyad
- 12,655
- 9
- 63
- 99
0
call this method onclick of email send button with email address and data as body and subject which you want to add as a field of Email composer.
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();
}
}
where data is the dataof your listView position

user1621629
- 765
- 7
- 19

Rishabh Bhardwaj
- 832
- 8
- 20