Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:05:57+00:00 2026-06-07T17:05:57+00:00

I am creating an android app that asks a user their birth day and

  • 0

I am creating an android app that asks a user their birth day and their birth month. I am using two spinners (one for the month and one for the days of the month).
I want the spinner for the days to change based on the month,
for example February has 29 days, so I want the day spinner to stop at the number 29. But I want the day spinner to go up as high as 31 if a month with 31 days is selected.

What is the best way to do this? I know I can use DatePicker, but I have never used it before and I only need a month and day (not the year).

debugText is just a textView that I created to test my spinner and make sure my coding was right so far.

//code

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.form);

    // Month

    monthSpinner = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter<CharSequence> monthAdapter = ArrayAdapter
            .createFromResource(this, R.array.month,
                    android.R.layout.simple_spinner_item);
    monthAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_item);
    monthSpinner.setAdapter(monthAdapter);

    monthName = "January";

    // Day

    daySpinner = (Spinner) findViewById(R.id.spinner2);
    final ArrayAdapter<CharSequence> dayAdapter = ArrayAdapter
            .createFromResource(this, R.array.day,
                    android.R.layout.simple_spinner_item);
    dayAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_item);
    daySpinner.setAdapter(dayAdapter);

    debugText = (TextView) findViewById(R.id.debugText);
    debugText.setText("Jaunary");

    daySpinner = (Spinner) findViewById(R.id.spinner2);

    monthSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub

            int monthPos = monthSpinner.getSelectedItemPosition();
            switch (monthPos) {
            case 0:
                debugText.setText("January");

                break;
            case 1:

                debugText.setText("February");

                break;
            case 2:
                debugText.setText("March");

                break;
            case 3:
                debugText.setText("April");

                break;
            case 4:
                debugText.setText("May");

                break;

            case 5:
                debugText.setText("June");

                break;
            case 6:

                debugText.setText("July");

                break;
            case 7:
                debugText.setText("August");

                break;
            case 8:
                debugText.setText("September");

                break;
            case 9:
                debugText.setText("October");

                break;

            case 10:
                debugText.setText("November");

                break;
            case 11:
                debugText.setText("December");

                break;
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
    });

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:05:58+00:00Added an answer on June 7, 2026 at 5:05 pm

    Really the DatePicker is the easiest way to do this, how else would you account for leap year to show the extra day on Feb? But if you insist on Spinners, here’s how I would do it:

    1. When the view is first shown, disable the daySpinner, and populate the monthSpinner and set the selection to nothing.
    2. In the OnItemSelected listener of monthSpinner, once it’s changed to a month, enable the daySpinner and based on the month selected, populate the daySpinner with the correct ArrayAdapter of days (e.g. you would have 4 arrays of day 1 to 28, 1 to 29, 1 to 30, 1 to 31) and set the adapter to daySpinner.
    3. When user changes the monthSpinner selection, you have to rebuild the daySpinner again.

    Finally, when OK button is clicked, just pick the month and day from the spinners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a app in android. In that i am using list view.
I'm creating an android app using Andengine. One part of the app requires users
i'm new in java/android app and i'm creating an app that uses user-location. I
I am creating an Android app that uses Twitter4J to read some user info.
I am currently creating an Android app that requires using the Android phone's name
so here is the problem. I am currently creating an Android app that is
I am creating an app on android but after hearing about sencha that it
if yes, is there a tutorial available for creating an android app using the
I am creating an android app that is basically a listing of information on
I am creating an Android app (API 8) that need to receive a lot

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.