2

我正在尝试为 ButterKnife 创建一个自定义侦听器注释,但我无法使其工作。这是我的注释:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.CLASS)
@ListenerClass(
        targetType = "com.maddogs.mymoney.views.CameraImageView",
        setter = "setCameraImageViewListener",
        type = "com.maddogs.mymoney.views.CameraImageViewListener",
        method = @ListenerMethod(
                name = "onCloseClick",
                parameters = {"com.maddogs.mymoney.views.CameraImageView"},
                returnType = "boolean",
                defaultReturn = "true"
        )
)
public @interface OnCloseClick {
    int[] value() default { View.NO_ID };
}

还有我的 CameraImageView:

 @Override
    public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() != MotionEvent.ACTION_DOWN
            &&(event.getX(0) <= this.getWidth()
            && event.getY(0) >= 0)
            && event.getX(0) >= this.getWidth() - closeBitmap.getWidth()
            && event.getY(0) <= closeBitmap.getHeight()){

        if(listener == null)
            throw new NullPointerException("CameraImageViewListener cannot be null");

        return listener.onCloseClick(this);
    }
    return super.onTouchEvent(event);
}

public void setCameraImageViewListener(CameraImageViewListener listener) {
        this.listener = listener;
    }

public static interface CameraImageViewListener{
    boolean onCloseClick(CameraImageView view);
}

还有我的项目结构:

结构

侦听器始终为空。怎么了??谢谢

4

1 回答 1

7

您需要将其添加到此列表ButterKnifeProcessor,以便注释处理器将其包含在代码生成中。

我一直在对不需要修改库的自定义注释的支持进行原型设计。没有关于何时发货的时间表。

于 2014-12-23T07:36:35.830 回答