Android Spinner: Get the selected item change event

前端 未结 16 2237
挽巷
挽巷 2020-11-22 16:47

How can you set the event listener for a Spinner when the selected item changes?

Basically what I am trying to do is something similar to this:

spinn         


        
16条回答
  •  悲哀的现实
    2020-11-22 17:49

    This will work intialize the spinner and findviewbyid and use this it will work

        Spinner schemeStatusSpinner;
    
      schemeStatusSpinner = (Spinner) dialog.findViewById(R.id.spinner);
    
    schemeStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView parentView, View selectedItemView, int position, long id) {
                // your code here
                if(schemeStatusSpinner.getSelectedItemId()==4){
                    reasonll.setVisibility(View.VISIBLE);
                }
                else {
                    reasonll.setVisibility(View.GONE);
                }
            }
    
            @Override
            public void onNothingSelected(AdapterView parentView) {
                // your code here
            }
    
        });
    

提交回复
热议问题