1:activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
2:res/values/cities.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="cities">
<item>Beijing</item>
<item>Shanghai</item>
<item>Guangzhou</item>
</string-array>
</resources>
3:MainActivity.java
public class MainActivity extends Activity {
private Spinner spinner=null;
private ArrayAdapter<CharSequence> adapter=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner=(Spinner)findViewById(R.id.spinner);
adapter=ArrayAdapter.createFromResource(this, R.array.cities,
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
}