One spinner shows radio buttons, the next doesn't

女生的网名这么多〃 提交于 2019-12-11 04:47:51

问题


I have two spinners, one above each other, like this:

<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"
/>

I set them like this

// 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);

They both display the correct data, but the first has radio buttons and the second doesn't. Any ideas why?

(R.layout.simple_spinner_item is the same as android.R.layout.simple_spinner_item, except it has android:textColor="@color/black" added.)


回答1:


In second spinner I think you have made a mistake Write

scaCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

So your code will be

// 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);


来源:https://stackoverflow.com/questions/6467689/one-spinner-shows-radio-buttons-the-next-doesnt

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