Update spinner items based on the selected item of another spinner

百般思念 提交于 2019-12-04 03:02:37

i would suggest u use the position returned by the onItemclickListener and use it in an array initializing array adapter for that spinner: like---

`

String hrs[]=getStringArray(R.array.departure_timeH6M_list);
  if(hrs[pos].equals("5"))
    { 

    }

`

and so on...

mayur rahatekar

When the Spinner change put the data Inside the adapter of the next spinner . And the just write adapter.notifyDataSetChanged(); The content Inside the next spinner will change.

If i understood your question correctly spinner is selecting a value by default.Yes that is correct if spinner sets to an adapter it will selects to first value. you have to write simple hack in onItemselectedListener to clear that default selection. take one int variable=-1 in my code it is ageposition im taking one boolean value age selected to find the default selection. if(ageselected) means spinner selected by user.

finally use ageSpinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

 class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
            if(ageposition==-1)
            {
                ageselected=false;
                ageposition=pos;
            }
            else
            {
                ageposition=pos;
                ageselected=true;
                childage=age[pos];
            }


        }
        public void onNothingSelected(AdapterView<?> parent) {
          // Dummy
        }
    }

Hope the above code helps you

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!