How to calculate age in Android Application using edit textHow to calculate age based on picked date in DatePickerDialog android?Is there a way to run Python on Android?How to save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?Is there a unique Android device ID?What is the difference between gravity and layout_gravity in Android?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?

A word that means "blending into a community too much"

How to safely destroy (a large quantity of) valid checks?

std::declval vs crtp, cannot deduce method return type from incomplete type

Increase speed altering column on large table to NON NULL

Is this a bug in plotting step functions?

Scientist couple raises alien baby

Printing Pascal’s triangle for n number of rows in Python

A map of non-pathological topology?

What does 思ってやっている mean?

Can all groups be thought of as the symmetries of a geometrical object?

What is the logic behind taxing money for property?

Can a human be transformed into a Mind Flayer?

Why does this query, missing a FROM clause, not error out?

How to make insert mode mapping count as multiple undos?

Is it possible for a vehicle to be manufactured without a catalytic converter?

How to “listen” to existing circuit

Did Apple bundle a specific monitor with the Apple II+ for schools?

Should I refuse being named as co-author of a bad quality paper?

PDF vs. PNG figure: why does figure load so much faster even if file sizes are the same?

Are polynomials with the same roots identical?

What are neighboring ports?

Has there been a multiethnic Star Trek character?

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

What aircraft was used as Air Force One for the flight between Southampton and Shannon?



How to calculate age in Android Application using edit text


How to calculate age based on picked date in DatePickerDialog android?Is there a way to run Python on Android?How to save an Android Activity state using save instance state?How do I center text horizontally and vertically in a TextView?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?How do I pass data between Activities in Android application?Is there a unique Android device ID?What is the difference between gravity and layout_gravity in Android?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am working on an android application that shows bar specials in the area and I want to make sure the only users that are using our app are 21+ years old. I have created a login/registration activity using edit texts and the information typed into the edit texts is sent to a mySQL database.



I have already searched for tutorials on youtube/stack overflow/google for help on this and I have only found datepicker tutorials. I am not sure how I would implement a datepicker tutorial into my project using edit texts.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



I am not sure what the output is supposed to look like or how to implement age validation into my project as a I am still fairly new to using Android Studio and I am open to new ideas etc. on how to best implement this into my project.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



buttonSignup.setOnClickListener(new View.OnClickListener() 
@Override
public void onClick(View view)

String email = signupInputEmail.getText().toString();
String password = signupInputPassword.getText().toString();
if (password.length()< 8)
signupInputPassword.setError("Your password must be at least 8 characters");
else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
signupInputEmail.setError("You must enter a valid email address");
else

submitForm();



);


submitForm()



private void submitForm() 

int selectedId = genderRadioGroup.getCheckedRadioButtonId();
String gender;
if(selectedId == R.id.female_radio_btn)
gender = "Female";
else
gender = "Male";

registerUser(signupInputName.getText().toString(),
signupInputEmail.getText().toString(),
signupInputPassword.getText().toString(),
gender,
signup_input_DOB.getText().toString());










share|improve this question
























  • stackoverflow.com/questions/33631453/…

    – John Joe
    Mar 25 at 3:20

















0















I am working on an android application that shows bar specials in the area and I want to make sure the only users that are using our app are 21+ years old. I have created a login/registration activity using edit texts and the information typed into the edit texts is sent to a mySQL database.



I have already searched for tutorials on youtube/stack overflow/google for help on this and I have only found datepicker tutorials. I am not sure how I would implement a datepicker tutorial into my project using edit texts.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



I am not sure what the output is supposed to look like or how to implement age validation into my project as a I am still fairly new to using Android Studio and I am open to new ideas etc. on how to best implement this into my project.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



buttonSignup.setOnClickListener(new View.OnClickListener() 
@Override
public void onClick(View view)

String email = signupInputEmail.getText().toString();
String password = signupInputPassword.getText().toString();
if (password.length()< 8)
signupInputPassword.setError("Your password must be at least 8 characters");
else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
signupInputEmail.setError("You must enter a valid email address");
else

submitForm();



);


submitForm()



private void submitForm() 

int selectedId = genderRadioGroup.getCheckedRadioButtonId();
String gender;
if(selectedId == R.id.female_radio_btn)
gender = "Female";
else
gender = "Male";

registerUser(signupInputName.getText().toString(),
signupInputEmail.getText().toString(),
signupInputPassword.getText().toString(),
gender,
signup_input_DOB.getText().toString());










share|improve this question
























  • stackoverflow.com/questions/33631453/…

    – John Joe
    Mar 25 at 3:20













0












0








0








I am working on an android application that shows bar specials in the area and I want to make sure the only users that are using our app are 21+ years old. I have created a login/registration activity using edit texts and the information typed into the edit texts is sent to a mySQL database.



I have already searched for tutorials on youtube/stack overflow/google for help on this and I have only found datepicker tutorials. I am not sure how I would implement a datepicker tutorial into my project using edit texts.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



I am not sure what the output is supposed to look like or how to implement age validation into my project as a I am still fairly new to using Android Studio and I am open to new ideas etc. on how to best implement this into my project.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



buttonSignup.setOnClickListener(new View.OnClickListener() 
@Override
public void onClick(View view)

String email = signupInputEmail.getText().toString();
String password = signupInputPassword.getText().toString();
if (password.length()< 8)
signupInputPassword.setError("Your password must be at least 8 characters");
else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
signupInputEmail.setError("You must enter a valid email address");
else

submitForm();



);


submitForm()



private void submitForm() 

int selectedId = genderRadioGroup.getCheckedRadioButtonId();
String gender;
if(selectedId == R.id.female_radio_btn)
gender = "Female";
else
gender = "Male";

registerUser(signupInputName.getText().toString(),
signupInputEmail.getText().toString(),
signupInputPassword.getText().toString(),
gender,
signup_input_DOB.getText().toString());










share|improve this question
















I am working on an android application that shows bar specials in the area and I want to make sure the only users that are using our app are 21+ years old. I have created a login/registration activity using edit texts and the information typed into the edit texts is sent to a mySQL database.



I have already searched for tutorials on youtube/stack overflow/google for help on this and I have only found datepicker tutorials. I am not sure how I would implement a datepicker tutorial into my project using edit texts.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



I am not sure what the output is supposed to look like or how to implement age validation into my project as a I am still fairly new to using Android Studio and I am open to new ideas etc. on how to best implement this into my project.



Here is part of my RegisterActivity.java file that I want to validate the data when the user clicks on register. I have already figured out how to validate email/password but do not know how to add date difference into my code. I have also added my submitForm function that is called....



buttonSignup.setOnClickListener(new View.OnClickListener() 
@Override
public void onClick(View view)

String email = signupInputEmail.getText().toString();
String password = signupInputPassword.getText().toString();
if (password.length()< 8)
signupInputPassword.setError("Your password must be at least 8 characters");
else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches())
signupInputEmail.setError("You must enter a valid email address");
else

submitForm();



);


submitForm()



private void submitForm() 

int selectedId = genderRadioGroup.getCheckedRadioButtonId();
String gender;
if(selectedId == R.id.female_radio_btn)
gender = "Female";
else
gender = "Male";

registerUser(signupInputName.getText().toString(),
signupInputEmail.getText().toString(),
signupInputPassword.getText().toString(),
gender,
signup_input_DOB.getText().toString());







android android-layout android-edittext






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 2:52









Hichem BOUSSETTA

1,46811418




1,46811418










asked Mar 24 at 19:56









ryaneryane

6




6












  • stackoverflow.com/questions/33631453/…

    – John Joe
    Mar 25 at 3:20

















  • stackoverflow.com/questions/33631453/…

    – John Joe
    Mar 25 at 3:20
















stackoverflow.com/questions/33631453/…

– John Joe
Mar 25 at 3:20





stackoverflow.com/questions/33631453/…

– John Joe
Mar 25 at 3:20












2 Answers
2






active

oldest

votes


















2














Convert the date of birth on the sign up input from String to Date like this:



String DOB = signup_input_DOB.getText().toString(); 

Date dateOfBirth=new SimpleDateFormat("dd/MM/yyyy").parse(DOB);


Then pass the date of birth to a method computing for the age:



int age = currentDate.getYear() - dateOfBirth.getYear();





share|improve this answer























  • Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

    – Vygintas B
    Apr 4 at 8:21


















1














Looks like you are following a long way to do this task. You can simply use DatePicker (Android Date Picker Official Docs



and set the selection range for the date, set the selected date (by the user) on the TextView. User Interface for handling the click event.



Create Interface.



public interface IOnItemClickListenerCountryStates 
void onAgeClick(String Date);







share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327976%2fhow-to-calculate-age-in-android-application-using-edit-text%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Convert the date of birth on the sign up input from String to Date like this:



    String DOB = signup_input_DOB.getText().toString(); 

    Date dateOfBirth=new SimpleDateFormat("dd/MM/yyyy").parse(DOB);


    Then pass the date of birth to a method computing for the age:



    int age = currentDate.getYear() - dateOfBirth.getYear();





    share|improve this answer























    • Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

      – Vygintas B
      Apr 4 at 8:21















    2














    Convert the date of birth on the sign up input from String to Date like this:



    String DOB = signup_input_DOB.getText().toString(); 

    Date dateOfBirth=new SimpleDateFormat("dd/MM/yyyy").parse(DOB);


    Then pass the date of birth to a method computing for the age:



    int age = currentDate.getYear() - dateOfBirth.getYear();





    share|improve this answer























    • Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

      – Vygintas B
      Apr 4 at 8:21













    2












    2








    2







    Convert the date of birth on the sign up input from String to Date like this:



    String DOB = signup_input_DOB.getText().toString(); 

    Date dateOfBirth=new SimpleDateFormat("dd/MM/yyyy").parse(DOB);


    Then pass the date of birth to a method computing for the age:



    int age = currentDate.getYear() - dateOfBirth.getYear();





    share|improve this answer













    Convert the date of birth on the sign up input from String to Date like this:



    String DOB = signup_input_DOB.getText().toString(); 

    Date dateOfBirth=new SimpleDateFormat("dd/MM/yyyy").parse(DOB);


    Then pass the date of birth to a method computing for the age:



    int age = currentDate.getYear() - dateOfBirth.getYear();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 4 at 6:52









    smga08smga08

    714




    714












    • Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

      – Vygintas B
      Apr 4 at 8:21

















    • Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

      – Vygintas B
      Apr 4 at 8:21
















    Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

    – Vygintas B
    Apr 4 at 8:21





    Getting age from years alone is not enough. You need to check month and day too. Your provided answer would be bad if checking for age is for legal reasons.

    – Vygintas B
    Apr 4 at 8:21













    1














    Looks like you are following a long way to do this task. You can simply use DatePicker (Android Date Picker Official Docs



    and set the selection range for the date, set the selected date (by the user) on the TextView. User Interface for handling the click event.



    Create Interface.



    public interface IOnItemClickListenerCountryStates 
    void onAgeClick(String Date);







    share|improve this answer



























      1














      Looks like you are following a long way to do this task. You can simply use DatePicker (Android Date Picker Official Docs



      and set the selection range for the date, set the selected date (by the user) on the TextView. User Interface for handling the click event.



      Create Interface.



      public interface IOnItemClickListenerCountryStates 
      void onAgeClick(String Date);







      share|improve this answer

























        1












        1








        1







        Looks like you are following a long way to do this task. You can simply use DatePicker (Android Date Picker Official Docs



        and set the selection range for the date, set the selected date (by the user) on the TextView. User Interface for handling the click event.



        Create Interface.



        public interface IOnItemClickListenerCountryStates 
        void onAgeClick(String Date);







        share|improve this answer













        Looks like you are following a long way to do this task. You can simply use DatePicker (Android Date Picker Official Docs



        and set the selection range for the date, set the selected date (by the user) on the TextView. User Interface for handling the click event.



        Create Interface.



        public interface IOnItemClickListenerCountryStates 
        void onAgeClick(String Date);








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 12 at 4:42









        DIVYA PRAKASHDIVYA PRAKASH

        1369




        1369



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327976%2fhow-to-calculate-age-in-android-application-using-edit-text%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript