There are several methods, if you have a link in your TextView
, you can simply enable the links using the method setLinksClickable () :
myTextView.setLinksClickable(true);
for example:
public void setLink(String link)
{
TextView post_link = (TextView)mView.findViewById(R.id.linkText);
post_link.setLinksClickable(true);
post_link.setText(link);
}
in this way all the "links" will be sensitive!
This form can also be configured directly in TextView
:
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="http://stackoverflow.com"
android:autoLink="web"
android:linksClickable="true"/>
The other way is through an Intent when clicking on the view:
post_link.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String url = "http://stackoverflow.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
});