2

我正在尝试在一个微调器的 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

        }

    });

但这东西行不通。请帮忙。

4

3 回答 3

0

改变 seriesspinner.setOnItemSelectedListener(new OnItemSelectedListener() {

seriesspinner.setOnItemSelectedListener(new View.OnItemSelectedListener() {
于 2013-10-21T12:56:11.750 回答
0

我目前没有手动编译器,但可能视图资源是错误的。以下。simple_spinner_item 和 simple_spinner_dropdown_item 需要更改

Spinner expiryMonthSpinner=new Spinner(...)
ArrayAdapter<String> expirymonth=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.expiry_month_array));
expiryMonthSpinner.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
于 2013-10-21T13:06:28.470 回答
0

问题出在我的布局高度上,这就是没有显示布局的原因。

于 2013-10-24T18:02:44.357 回答