【发布时间】:2021-04-27 06:50:57
【问题描述】:
你好,希望你们一切都好
我的验证有问题,我尝试了很多方法,但没有一个有效
我有编辑文本,我想输入验证,只允许输入 1 到 15 之间的数字,但它没有任何帮助,请提供帮助
String pet_name=petname.getText().toString();
String pet_type=ptype.getText().toString();
String pet_age=page.getText().toString();
String pet_gender=pgender.getText().toString();
String pet_location=plocation.getText().toString();
String pet_des=pdes.getText().toString();
String pet_img=petimg.getText().toString();
int inputInt = Integer.parseInt(page.getText().toString());
if(pet_name.equals(""))
petname.setError("User name Should not be empty");
else if(!pet_name.matches(namevalid))
petname.setError("Should be Only letters");
else if(pet_type.equals(""))
ptype.setError("Should not be empty");
else if(!pet_type.startsWith("Cat")&& !pet_type.startsWith("Dog"))
ptype.setError("Should be Only Cat or Dog");
else if(pet_age.equals(""))
page.setError("Should not be empty");
else if (inputInt <= 15 && inputInt >= 1 ) ;
page.setError("Should be be between 1 to 15 year");
当我添加此代码程序停止工作时,问题就在这里
else if (inputInt <= 15 && inputInt >= 1 ) ;
page.setError("Should be be between 1 to 15 year");
enter code here
【问题讨论】:
-
条件应该是 else if (inputInt >= 16 || inputInt
标签: java android android-studio validation