在Activity中添加如下代码:
private static final String[] mAPDU={"0x00, 0x84, 0x00, 0x00, 0x08 ","0x00, 0xc0, 0x00, 0x00, 0x0a","..."};
private Spinner spinner;
private ArrayAdapter adapter;
private static int mApduIndex = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.iccard);
mQuery = (EditText) findViewById(R.id.textViewQuery);
mRuternData = (EditText) findViewById(R.id.textViewRuternData);
spinner = (Spinner) findViewById(R.id.SpinnerAPDU);
//将可选内容与ArrayAdapter连接起来
adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item,mAPDU);
//设置下拉列表的风格
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//将adapter 添加到spinner中
spinner.setAdapter(adapter);
//添加事件Spinner事件监听
spinner.setOnItemSelectedListener(new SpinnerSelectedListener(){});
//设置默认值
spinner.setVisibility(View.VISIBLE);
//使用数组形式操作
abstract class SpinnerSelectedListener implements OnItemSelectedListener{
public void onItemSelected(AdapterView> arg0, View arg1, int arg2,
long arg3) {
mApduIndex = arg2;
}
public void onNothingSelected(AdapterView> arg0) {
}
}