Skip to content Skip to sidebar Skip to footer

How To Get Spinner Value Depending Upon The Other Spinner

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. Anothe

Solution 1:

It's really simple. Put a OnItemSelectedListener() on the month spinner, adding your own listener which initializes the day spinner with the correct values


Solution 2:

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

        }
    });

Post a Comment for "How To Get Spinner Value Depending Upon The Other Spinner"