1. Download our Official Android App: Forums for Android!

Apps EditText using if statement to check for numeric input only

Discussion in 'Android Development' started by Ben Richard, Mar 28, 2016.

  1. Ben Richard

    Ben Richard Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    7
    Joined:
    Mar 22, 2016

    Mar 22, 2016
    7
    0
    15
    Male
    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 ;

    }
     

    Advertisement

  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator
    Rank:
     #1
    Points:
    4,488
    Posts:
    38,270
    Joined:
    Jun 23, 2010

    Jun 23, 2010
    38,270
    47,475
    4,488
    Male
    Douglas, MA
    Application Development thread moved to the Development forum for better exposure.:)
     
  3. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    Looks ok, what's the problem?
     
  4. Ben Richard

    Ben Richard Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    7
    Joined:
    Mar 22, 2016

    Mar 22, 2016
    7
    0
    15
    Male
    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
     
  5. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    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.
     
    #5 LV426, Mar 28, 2016
    Last edited: Mar 28, 2016
  6. Ben Richard

    Ben Richard Lurker
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    7
    Joined:
    Mar 22, 2016

    Mar 22, 2016
    7
    0
    15
    Male
    is there an example which shows...a user entering one input lets say the user enters 9 and it outputs 9 editTexts
     

Share This Page

Loading...