3

我需要覆盖默认的 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;
        }
    }

}

我错过了setInstance创建 LinkMovementMethod 新实例的方法。

4

0 回答 0