我正在尝试在一个微调器的 onItemSelected 事件上使用 java 将新微调器添加到 LinearLayout。这是我的代码的样子:
seriesspinner=(Spinner) findViewById(R.id.series_spinner);
seriesspinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View item,
int position, long id) {
// TODO Auto-generated method stub
View dynamicPlace=findViewById(R.id.dynamic_spinners_layout);
String selectedItem=parent.getItemAtPosition(position).toString().toLowerCase();
((LinearLayout)dynamicPlace).removeAllViews();
if(selectedItem.equalsIgnoreCase("futures")){
Spinner expiryMonthSpinner=new Spinner(getApplicationContext());
expiryMonthSpinner.setLayoutParams(new LayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT)));
ArrayAdapter<String> expirymonth=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, getResources().getStringArray(R.array.expiry_month_array));
expiryMonthSpinner.setAdapter(expirymonth);
Toast.makeText(getApplicationContext(), selectedItem, Toast.LENGTH_LONG).show();
((LinearLayout)dynamicPlace).addView(expiryMonthSpinner);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
但这东西行不通。请帮忙。