我正在使用Android验证Saripaar库进行验证,我需要将我的XML资源字符串分配给邮件属性, 我无法通过此范围内的getResources.getStrings(R.strings.myString)获取系统资源,因为在本地范围之外无法访问“this”。
public class signup extends Activity
{
@Order(1)
@Email(message = "Please Type Correct Email!")
private EditText email;
//onCreate()....
}
答案 0 :(得分:1)
尝试以下
@Email(messageResId = R.string.invalid_email)
@BindView(R.id.et_mail)
EditText etMail;
From source code of saripar
@ValidateUsing(EmailRule.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Email {
boolean allowLocal()
default false;
int sequence() default -1;
int messageResId() default -1;
String message() default "Invalid email";
}