Android Spinner 下拉列表
private Spinner spinner ;
private List<String> list ;
private ArrayAdapter<String> arrayAdapter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
spinner=(Spinner) findViewById(R.id. spinner1);
list= new ArrayList<String>();
//NEW arrayAdapter适配器
arrayAdapter=new ArrayAdapter<String>(this ,android.R.layout.simple_spinner_dropdown_item, list);
//adapter设置下拉列表样式
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter( arrayAdapter);
//设置监听器
spinner.setOnItemSelectedListener( new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
stareblankly.cn