我需要覆盖默认的LinkMovementMethod。但它调用默认的LinkMovementMethod。这是代码:
class MovementCheck extends LinkMovementMethod {
@Override
public boolean onTouchEvent(TextView widget,
Spannable buffer, MotionEvent event ) {
try {
Log.d("sg", "check check check");
return super.onTouchEvent( widget, buffer, event ) ;
} catch( ActivityNotFoundException ex ) {
Log.d("sg", "Error");
return true;
}
}
...
Spanned spanned = Html.fromHtml(rules.getObjects().get(0).getDescription());
rulesBody.setText(spanned);
rulesBody.setMovementMethod(MovementCheck.getInstance());
找出正确的实现..可能有用:
class MovementCheck extends LinkMovementMethod {
private static MovementCheck sInstance;
public static MovementCheck getInstance() {
if (sInstance == null)
sInstance = new MovementCheck();
return sInstance;
}
@Override
public boolean onTouchEvent(TextView widget,
Spannable buffer, MotionEvent event ) {
try {
return super.onTouchEvent( widget, buffer, event ) ;
} catch(ActivityNotFoundException ex) {
CrashLytics.logException(ex);
new UtilitySingleton().ShowToast("Link Broken...!!");
return true;
}
}
}
我错过了创建LinkMovementMethod新实例的setInstance
方法。