[android]代码库
myTextView = (TextView) findViewById(R.id.myTextView);
mySpinner = (Spinner) findViewById(R.id.mySpinner);
adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item,
countriesStr);
/* myspinner_dropdown为自定义下拉菜单样式定义在res/layout目录下 */
adapter.setDropDownViewResource(R.layout.myspinner_dropdown);
/* 将ArrayAdapter加入Spinner对象中 */mySpinner.setAdapter(adapter);
/* 将mySpinner加入OnItemSelectedListener */
mySpinner
.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
/* 将所选mySpinner的值带入myTextView中 */
myTextView.setText("选择的是" + countriesStr[arg2]);
/* 将mySpinner显示 */
arg0.setVisibility(View.VISIBLE);
}
@Override
public void onNothingSelected(AdapterView arg0) {
// TODO Auto-generated method stub
}
});