您可以嘗試使用Linkify自定義模式。
但是,如果不適合你的需求,你可以試試這個:
SpannableString ss = new SpannableString("Hi this is @Naveen. I'll meet @Peter in the evening.. Would you like to join @Sam??");
ClickableSpan clickableSpanNaveen = new ClickableSpan() {
@Override
public void onClick(View textView) {
//Do Stuff for naveen
}
};
ClickableSpan clickableSpanPeter = new ClickableSpan() {
@Override
public void onClick(View textView) {
//Do Stuff for peter
}
};
ClickableSpan clickableSpanSam = new ClickableSpan() {
@Override
public void onClick(View textView) {
//Do Stuff for sam
}
};
ss.setSpan(clickableSpanNaveen, 11, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(clickableSpanPeter, 29, 35, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(clickableSpanSam, 76, 79, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView contentTextView=(TextView)userHeader.findViewById(R.id.contentTextView);
contentTextView.setText(ss);
contentTextView.setMovementMethod(LinkMovementMethod.getInstance());
http://stackoverflow.com/questions/4025770/android-launch-activity-from-clickable-text – Daniel 2013-03-05 12:04:27
@ Daniel Yeaah早些時候看到,但我不明白:( – Naveen 2013-03-05 12:07:04
mmm ...試圖看看Linkify看文檔 – 2013-03-05 14:52:33