我有两个旋转器,一个在彼此之上,像这样:
<Spinner
android:layout_height="wrap_content"
android:id="@+id/CitySpinner"
android:layout_width="fill_parent"
android:prompt="@string/city_prompt"
/>
<Spinner
android:layout_height="wrap_content"
android:id="@+id/CountrySpinner"
android:layout_width="fill_parent"
android:prompt="@string/country_prompt"
/>
我像这样设置它们
// set the data adapter for the city spinner
spnCity = (Spinner) findViewById(R.id.CitySpinner);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.simple_spinner_item,
mDbHelper.getCities(),
new String[] { KEY_CITY },
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCity.setAdapter(adapter);
// set the data adapter for the country spinner
spnCountry = (Spinner) findViewById(R.id.ProviderSpinner);
SimpleCursorAdapter scaCountries = new SimpleCursorAdapter(this,
R.layout.simple_spinner_item,
mDbHelper.getCountries(),
new String[] { KEY_COUNTRY },
new int[] {android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCountry.setAdapter(scaCountries);
它们都显示正确的数据,但第一个有单选按钮而第二个没有。有什么想法吗?
(R.layout.simple_spinner_item与android.R.layout.simple_spinner_item相同,只是添加了android:textColor="@color/black"
。)
答案 0 :(得分:2)
在第二个旋转器中,我认为你犯了一个错误 写
scaCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
所以你的代码将是
// set the data adapter for the country spinner
spnCountry = (Spinner) findViewById(R.id.ProviderSpinner);
SimpleCursorAdapter scaCountries = new SimpleCursorAdapter(this,
R.layout.simple_spinner_item,
mDbHelper.getCountries(),
new String[] { KEY_COUNTRY },
new int[] {android.R.id.text1});
scaCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCountry.setAdapter(scaCountries);