java、B.java、C.java 在这三个类中我对特定字符串进行相同的验证。是否可以编写一个类并在需要的地方将其作为类中的方法调用,下面是我分别在上述三个类中使用的手机号码的验证。
A.java
mobile = (EditText) findViewById(R.id.app_mobile);
String ap_Mobile_No = mobile.getText().toString();
if (ap_Mobile_No.equals(null) || (ap_Mobile_No.length() != 10) || ap_Mobile_No.startsWith("0")){
mobile.setError("E");
result = false;
}
B.java
EditText mobile = (EditText) findViewById(R.id.gua_mobile);
String gu_Mobile_No = mobile.getText().toString();
if (gu_Mobile_No.equals("") || gu_Mobile_No.length() != 10 || gu_Mobile_No.startsWith("0")) {
mobile.setError(ssbuilder);
result = false;
}
最佳答案
您可以为此验证创建类并使用 Method 调用此类;
public class Validation
{
public static boolean checkValidation(arguments)
{
check your validation here.
return true or false;
}
}
关于java - 如何从一个类调用另一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18013758/