Android - how to get another value of selected item on spinner

前端 未结 1 2033
渐次进展
渐次进展 2021-01-25 20:36

I\'ve a rest response as below, and i need to populate the output to spinner. I\'ve been successfully pass the \"name\" to spinner and it\'s works. But I also need get the \"id\

相关标签:
1条回答
  • 2021-01-25 21:00

    Try this

    To get ID :

    provinceResponseData.get(spinner.getSelectedItemPosition()).getId();
    

    Add spinner listener :

    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            // call the service and pass the parameter
            serviceCall(provinceResponseData.get(spinner.getSelectedItemPosition()).getId());
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
            // your code here
        }
    
    });
    
    0 讨论(0)
提交回复
热议问题