There's no shortage of posts regarding Linkify and automatically making part of the TextView clickable. Just search for "android textview hyperlink" and you'll get a fair idea.
TextView tvMessage = (TextView) findViewById(R.id.txtMsg);
tvMessage.setAutoLinkMask(Linkify.ALL);
And the result would be something like...
But when you don't want the text to include http:// is when you'll have to look elsewhere.
To get this, it's really simple. You can even make a quick TextView subclass out of it.
/**
* Sets a hyperlink style to the textview.
*/
public static void makeTextViewHyperlink(TextView tv) {
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(tv.getText());
ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(ssb, TextView.BufferType.SPANNABLE);
}
And to set up the click handler, just use an ordinary OnClickListener so you can handle the click any way you want.
TextView tv = (TextView) findViewById(R.id.linkRecipes);
Utils.makeTextViewHyperlink(tv);
tv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), RecipeActivity.class);
startActivity(intent);
}
});
While you're at it, check out my Diablo II Runewords app!