• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps EditText using if statement to check for numeric input only

Ben Richard

Lurker
Mar 22, 2016
7
0
How do I check if user enters something and it will prompt the user until he enters something and will not let him go on next page? here is the code

if (howManyQuestions != null && howManyQuestions.getText().length() != 0) {//check if user enters a numeric attribute
name2 = howManyQuestions.getText().toString();

}
else if(howManyQuestions.getText().toString().length() == 0) {//check if user doesn't enter a numeric attribute
Toast.makeText(this, "please select how many answers you are looking for..", Toast.LENGTH_SHORT).show();
return ;

}
 
So to do this you will need to dynamically add editText views at runtime.
Start by defining a layout for your new Activity, which contains one EditText. Then depending on the number of EditTexts required by the user, you can add more as required.
There are plenty of examples on how to do this.
 
Last edited by a moderator:
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones