OnLongClickListener longClickListener = new View.OnLongClickListener() {
public boolean onLongClick(View arg0) {
CharSequence mText = tv.getText();
if (mText instanceof Spanned) {
int selStart = tv.getSelectionStart();
int selEnd = tv.getSelectionEnd();
selStart = ((Spanned) mText).getSpanStart(mText);
selEnd = ((Spanned) mText).getSpanEnd(mText);
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
URLSpan[] urls = ((Spanned) mText).getSpans(min, max,
URLSpan.class);
if (urls.length == 1) {
String url = urls[0].getURL();
Toast.makeText(TestActivity.this, "url: " + url,
Toast.LENGTH_SHORT).show();
return true;
}
}
return false;
}
};