Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get spinner value depending upon the other spinner
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Here is my code where I have the two spinners:</p> <pre><code> @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /*************day spinner**********/ Spinner day = (Spinner) findViewById(R.id.spinner2); ArrayAdapter&lt;CharSequence&gt; 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&lt;CharSequence&gt; monthadapter = ArrayAdapter.createFromResource( this, R.array.item_month, android.R.layout.simple_spinner_item); monthadapter.setDropDownViewResource(R.layout.spinner_layout); month.setAdapter(monthadapter); }} </code></pre> <p>My Xml where the spinners are defined :</p> <pre><code> &lt;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" /&gt; &lt;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" /&gt; </code></pre> <p>my spinner_layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;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" /&gt; </code></pre> <p>my day array </p> <pre><code>&lt;string name="day_picker"&gt;Select an iten&lt;/string&gt; &lt;string-array name="item_day"&gt; &lt;item&gt;1&lt;/item&gt; &lt;item&gt;2&lt;/item&gt; &lt;item&gt;3&lt;/item&gt; &lt;item&gt;4&lt;/item&gt; &lt;item&gt;5&lt;/item&gt; &lt;item&gt;6&lt;/item&gt; &lt;item&gt;7&lt;/item&gt; &lt;item&gt;8&lt;/item&gt; &lt;item&gt;9&lt;/item&gt; &lt;item&gt;10&lt;/item&gt; &lt;item&gt;11&lt;/item&gt; &lt;item&gt;12&lt;/item&gt; &lt;item&gt;13&lt;/item&gt; &lt;item&gt;14&lt;/item&gt; &lt;item&gt;15&lt;/item&gt; &lt;item&gt;16&lt;/item&gt; &lt;item&gt;17&lt;/item&gt; &lt;item&gt;18&lt;/item&gt; &lt;item&gt;19&lt;/item&gt; &lt;item&gt;20&lt;/item&gt; &lt;item&gt;21&lt;/item&gt; &lt;item&gt;22&lt;/item&gt; &lt;item&gt;23&lt;/item&gt; &lt;item&gt;24&lt;/item&gt; &lt;item&gt;25&lt;/item&gt; &lt;item&gt;26&lt;/item&gt; &lt;item&gt;27&lt;/item&gt; &lt;item&gt;28&lt;/item&gt; &lt;item&gt;29&lt;/item&gt; &lt;item&gt;30&lt;/item&gt; &lt;item&gt;31&lt;/item&gt; &lt;/string-array&gt; </code></pre> <p>my month array</p> <pre><code>&lt;resources&gt; &lt;string name="month_picker"&gt;Select an item&lt;/string&gt; &lt;string-array name="item_month"&gt; &lt;item&gt;January&lt;/item&gt; &lt;item&gt;February&lt;/item&gt; &lt;item&gt;March&lt;/item&gt; &lt;item&gt;April&lt;/item&gt; &lt;item&gt;May&lt;/item&gt; &lt;item&gt;June&lt;/item&gt; &lt;item&gt;July&lt;/item&gt; &lt;item&gt;August&lt;/item&gt; &lt;item&gt;September&lt;/item&gt; &lt;item&gt;October&lt;/item&gt; &lt;item&gt;November&lt;/item&gt; &lt;item&gt;December&lt;/item&gt; &lt;/string-array&gt; &lt;/resources&gt; </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload