• 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

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 ;

}
 
Basically when the user enters a number I need it to open a new activity showing it as a editText box so if the user enters 6 it should show 6 editText boxes
 
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:
Back
Top Bottom