TextView執行click功能:ide
借用SpannableString或SpannableStringBuilder,二者區別:後者多了修改文本功能ui
代碼片斷:this
TextView tv = (TextView) findViewById(R.id.textview1);
String t = "顯示下個activity";
SpannableString ss = new SpannableString(t);
ss.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
Intent i = new Intent(TextViewActivity.this,CanvasActivity.class);
startActivity(i);
}
}, 0, t.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(ss);
tv.setMovementMethod(LinkMovementMethod.getInstance());get