I have开发者_如何学编程 implemented the official Spinner tutorial, but when I run it, the spinner widget is malformed, I have attached this screenshot:
If instead of filling the spinner from code, I use the android:entries in the XML, the widget shows correctly.
Anyone knows why?
EDIT: Here is my code. And here is the code for main.xml and strings.xml
EDIT2: Ok, now I remember that my code was not extracted from the tutorial, but from the SDK samples directory, so the tutorial is fine, but not the SDK sample.
You have to pay close attention in tutorials. In that tutorial when they instantiate the ArrayAdapter
they reference another layout than you do.
You've referenced the android.R.layout.simple_spinner_dropdown_item
where they have referenced the android.R.layout.simple_spinner_item
layout.
The first one is used for displaying items in a drop-down and the second one is used to display the default Spinner
appearance.
精彩评论