import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
public class MySpinner extends Activity { //data that will be used as a spinner options
private static String data[] = {"one", "two", "three"}; /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//main.xml file contains spinner
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
//create your own adapter
MySpinnerAdapter adapter = new MySpinnerAdapter(this,R.layout.custom_spinner_row,R.id.text, data );
//set your custom adapter
spinner.setAdapter( adapter );
}
private class MySpinnerAdapter extends ArrayAdapter
{
public MySpinnerAdapter(Context context, int resource, int textViewResourceId, String[] objects)
{ super(context, resource, textViewResourceId, objects);
}
}
R.layout.custom_spinner_row是只含有一个linear并包含一个叫text的文本框
如果你想做的更好看些 ,那你还的重写 getView() method