//ActivitySpinner.java
package android.ActivityUI;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
public class ActivitySpinner extends Activity{
Spinner spinner1;
private ArrayAdapter<String> nCountries;
private List<String> allCountries;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.spinner);
setTitle("Spinner");
spinner_select();
}
private static final String[] mCountries = {"China","Russia","German","USA"};
private void spinner_select(){
spinner1 = (Spinner)findViewById(R.id.spinner1);
allCountries = new ArrayList<String>();
for(int i=0;i < mCountries.length;i++){
allCountries.add(mCountries[i]);
}
nCountries = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,allCountries);
nCountries.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(nCountries);
}
}
//spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Spinner
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="@+id/spinner1">
</Spinner>
</LinearLayout>