我想在EditText
的输入中添加验证,以便用户输入1-12之外的数字时,应用程序不会移动到下一个Activity
,而是我想要它什么都不做,允许用户重新输入有效的号码。我不知道该怎么做。
当前代码EditText
部分:
//Setting up next activity to open via intent
Intent intent = new Intent(this, PracticeTest.class);
//Validation to ensure number is between 1 and 12
if (convertedNumber2 >= 1 && convertedNumber2 <= 12) {
//pass int value
intent.putExtra("convertedNumber2", convertedNumber2);
} else {
}
//open activity
startActivity(intent);
答案 0 :(得分:0)
//Validation to ensure number is between 1 and 12
if (convertedNumber2 >= 1 && convertedNumber2 <= 12) {
//Setting up next activity to open via intent
Intent intent = new Intent(this, PracticeTest.class);
//pass int value
intent.putExtra("convertedNumber2", convertedNumber2);
//open activity
startActivity(intent);
} else {
Toast.makeText(this, "Opss, wrong value!", Toast.LENGTH_SHORT).show();
}