Android- Multiple Spinners

后端 未结 2 1732
無奈伤痛
無奈伤痛 2020-12-31 09:36

I have this code:

package lijap.app.starcraft2counters;

import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Enviro         


        
2条回答
  •  说谎
    说谎 (楼主)
    2020-12-31 09:58

    Check this one

    yearDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
    
        public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) 
        {
            selectedyear = parentView.getSelectedItemPosition();
            drpyear      = yearDropdown.getSelectedItem().toString();
    
            //your code here
    
        }
    
        public void onNothingSelected(AdapterView parentView) 
        {
            selectedyear = 0;
            //return;
        }
    });
    
    monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
    
        public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) 
        {
            //your code here
    
    
        }
    
        public void onNothingSelected(AdapterView parentView) 
        {
            selectedmonth = 0;
            //return;
        }
    });
    
    dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() {
    
        public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) 
        {
            //your code here
    
        }
    
        public void onNothingSelected(AdapterView parentView) 
        {
            selectedday = 0;
        }
    });
    

    you need to create each adapter for every spinner.

       adapterYear = new ArrayAdapter(this,android.R.layout.simple_spinner_item);
       yearDropdown.setAdapter(adapterYear);
    
       adapterMonth = new ArrayAdapter(this,android.R.layout.simple_spinner_item);
       monthDropdown.setAdapter(adapterMonth);
    
       adapterDays = new ArrayAdapter(this,android.R.layout.simple_spinner_item);
       dayDropdown.setAdapter(adapterDays);
    

提交回复
热议问题