资 源 简 介
Android 下拉列表选值初级实例,通过血型选择来练习下拉框的使用。
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_TextView = (TextView) findViewById(R.id.TextView1);
m_Spinner = (Spinner) findViewById(R.id.Spinner1);
//将可选内容与ArrayAdapter连接
adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, m_Countries);
//设置下拉列表的风格
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//将adapter添加到m_Spinner中
m_Spinner.setAdapter(adapter);
//添加Spinner事件监听
m_Spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3)
{
m_TextView.setText("你的血型是:" + m_Countries[arg2]);
//设置显示当前选择的项
arg0.setVisibility(View.VISIBLE);
}
});