If generated programmatically in Android 2.0, Android spinner does not render correctly
•
Android
This code is written in Spinner's layout / XML file:
<Spinner
android:id="@+id/planets_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/planets_array" />
Java code in oncreate (bundle savedinstancestate) {} in mainactivity.java:
ArrayList<String> spinnerArray = new ArrayList<String>();
spinnerArray.add("one");
spinnerArray.add("Jupiter");
spinnerArray.add("Mercury");
spinnerArray.add("Venus");
spinnerArray.add("Earth");
Spinner spinner = new Spinner(this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray);
spinner.setAdapter(spinnerArrayAdapter);
How can it go wrong?
resolvent:
You are using the wrong resource... The checkable style you are using is only applicable to drop-down resources
The following should work (note that simple_spinner_dropdown_item! = simple_spinner_item):
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerArray);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码