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 7883097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:26:35+00:00 2026-06-03T04:26:35+00:00

I have two spinner item. One is my Day spinner , another is my

  • 0

I have two spinner item. One is my Day spinner , another is my Month Spinner.
If I select month February from month spinner and if I select day as 30 ,it should not be done.

Another example: month April has 30 days , so if someone selects Month as April and day as 31st ,then it is not correct. Please tell me how to do get the value of one spinner corresponding to the value of another spinner.

Here is my code where I have the two spinners:

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 /*************day spinner**********/

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

        /*****************month spinner**********************/


        Spinner month  = (Spinner) findViewById(R.id.spinner3);
        ArrayAdapter<CharSequence> monthadapter = ArrayAdapter.createFromResource(
                this, R.array.item_month, android.R.layout.simple_spinner_item);
        monthadapter.setDropDownViewResource(R.layout.spinner_layout);
        month.setAdapter(monthadapter);


}}

My Xml where the spinners are defined :

    <Spinner
            android:id="@+id/spinner2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/spinner3"
            android:layout_alignTop="@+id/textView4"
            android:layout_toLeftOf="@+id/textView3" />
   <Spinner
            android:id="@+id/spinner3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/spinner2"
            android:layout_toLeftOf="@+id/textView3"
            android:layout_toRightOf="@+id/textView5" />

my spinner_layout:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/spinnerTarget"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textColor="#000000"
          android:textSize="12pt"
/>

my day array

<string name="day_picker">Select an iten</string>
<string-array name="item_day">
    <item>1</item>
    <item>2</item>
    <item>3</item>
    <item>4</item>
    <item>5</item>
    <item>6</item>
     <item>7</item>
    <item>8</item>
    <item>9</item>
    <item>10</item>
    <item>11</item>
    <item>12</item>
     <item>13</item>
    <item>14</item>
    <item>15</item>
    <item>16</item>
    <item>17</item>
    <item>18</item>
     <item>19</item>
    <item>20</item>
    <item>21</item>
    <item>22</item>
    <item>23</item>
    <item>24</item>
     <item>25</item>
    <item>26</item>
    <item>27</item>
    <item>28</item>
    <item>29</item>
    <item>30</item>
    <item>31</item>

</string-array>

my month array

<resources>
    <string name="month_picker">Select an item</string>
    <string-array name="item_month">
        <item>January</item>
        <item>February</item>
        <item>March</item>
        <item>April</item>
        <item>May</item>
        <item>June</item>
         <item>July</item>
        <item>August</item>
        <item>September</item>
        <item>October</item>
        <item>November</item>
        <item>December</item>
         </string-array>
</resources>

If I select any month I want to get corresponding no. of days automatically in day-spinner
Note: I do not want any error message after clicking a button. thanks in advance.

  • 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-03T04:26:36+00:00Added an answer on June 3, 2026 at 4:26 am
    month.setOnItemSelectedListener(new OnItemSelectedListener() {
    
            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // TODO Auto-generated method stub
                List<String> s = Arrays.asList(getResources().getStringArray(R.array.item_day));
                if (pos == 0 || pos == 2 || pos == 4 || pos == 8 || pos == 9
                        || pos == 11) {
                    ArrayAdapter<String> dayadapter = new  ArrayAdapter<String>(Latlondemo.this, android.R.layout.simple_spinner_item,s);
                    day.setAdapter(dayadapter);
                } else if (pos == 1) {
                    s = s.subList(0,28);                    
                    ArrayAdapter<String> dayadapter = new  ArrayAdapter<String>(Latlondemo.this, android.R.layout.simple_spinner_item,s);
                    day.setAdapter(dayadapter);
                } else {
                    s = s.subList(0,30);                    
                    ArrayAdapter<String> dayadapter = new  ArrayAdapter<String>(Latlondemo.this, android.R.layout.simple_spinner_item,s);
                    day.setAdapter(dayadapter);
                }
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
    
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have a custom spinner that uses two custom views, one for the drop
i have two spinners. If in the first one the Item Diesel is selected
I have two spinners. When an item is selected from spinner1, I want spinner2's
I have Two spinner(Subject and Chapter),I crate two table(Chapter,subject). I add all subject name
I have two questions. How can I get the spinner in the figure below
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two spinners one named cuisine and other area. I m calling the
I have a UITableView which from an external RSS feed. When you select a
I have two spinners (day_spin and time_spin) in one Activity . I want to

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.