ArrayList<SpinnerItem> aList = new ArrayList<SpinnerItem>(); aList.add(new SpinnerItem(String.valueOf(CategoryType.Cost.ordinal()),getString(R.string.COST))); aList.add(new SpinnerItem(String.valueOf(CategoryType.income.ordinal()),getString(R.string.IMCOME))); ArrayAdapter<SpinnerItem> aAdapter = new ArrayAdapter<SpinnerItem>(this,android.R.layout.simple_spinner_item,aList); spinnerCategoryType = (Spinner)findViewById(R.id.spCategoryType); aAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); //设置下拉菜单的风格 spinnerCategoryType.setAdapter(aAdapter);
主要是利用ArrayList存贮KEY-VALUE,并绑定到ArrayAdapter中,最后显示在spinner中。