Reputation: 911
I have an email address in a string resource:
<string name="send_email">Send us an email [email protected]</string>
This string resource is part of a string array that is being used by a listView with an adapter.
Is there a way to make the email address a link so it will open the mail client upon clicking it? I have looked at linkify but from what I saw it only works on textViews.
Any ideas?
Thanks!
Upvotes: 2
Views: 462
Reputation: 5451
You can use below code for making text linkable:
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(1.1f), 0,6, 0); // set size
ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 6, 0);// It will set first six letter to red color
SpannableString ss = new SpannableString("Click here to learn more");
ss.setSpan(clickableSpan, 0, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // It will make first 10 letters to clickable
tv.setText(ss);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(ss1);
Upvotes: 1
Reputation: 10724
In the xml view of the listitem which you populate with the email adress add this to the xml
android:autoLink="email"
You can also use the Linkify class to make each link and email adress clickable in your list. And yes, it works on textviews but the Listview contains textviews which you can access. You can either use custom views for your Listview adapter or use the standard simple views that android provide, but also these consist of textviews which you can access.
Upvotes: 1
Reputation: 6855
OnClick on the mail address just use the below code to call the intent
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "[email protected]" });// selected email adress.
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Upvotes: 0