
如何创建相同的自定义注释?
解决方法 (披露:我是作者)Saripaar v2允许您定义自定义注释.
这是你做的事情.
步骤1如下定义您的自定义注释.确保您有一个RUNTIME保留策略,并且您的注释必须针对FIELD元素类型.消息和messageResID属性是必需的,因此请注意名称和类型.
@ValIDateUsing(HaggleRule.class)@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.FIELD)public @interface Haggle { public int messageResID() default -1; // Mandatory attribute public String message() default "Oops... too pricey"; // Mandatory attribute public int sequence() default -1; // Mandatory attribute public double maximumAskingPrice(); // Your attributes} 步骤2通过扩展AnnotationRule类定义您的规则.
public class HaggleRule extends AnnotationRule<Haggle,Double> { protected HaggleRule(Haggle haggle) { super(haggle); } @OverrIDe public boolean isValID(Double data) { boolean isValID = false; double maximumAskingPrice = mRuleAnnotation.maximumAskingPrice(); // Do some cLever valIDation.... return isValID; }} 步骤3注册您的规则.
ValIDator.registerannotation(Haggle.class); // Your annotation class instance
就那么简单.看看源代码,如果你想的话. Saripaar v2现已在Maven Central上市.
总结以上是内存溢出为你收集整理的向Android Saripaar添加自定义注释全部内容,希望文章能够帮你解决向Android Saripaar添加自定义注释所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)