三个旋转器同时

时间:2012-05-23 18:10:11

标签: android spinner

我在同一个xml中有三个微调器,一次只有一个正常工作,每次都是一个不同的工作。在布局中,所有微调器都会出现,但不会显示它们所具有的字符串,因此无法选择任何微调器的字符串

        final Spinner sCategories = (Spinner)findViewById(R.id.spCategories);
    ArrayAdapter<String> categoryAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item,categoriesVector);
    sCategories.setAdapter(categoryAdapter);


    sCategories.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            ItemToAdd.category=sCategories.getSelectedItem().toString();
        }


        public void onNothingSelected(AdapterView<?> parentView) {
            // your code here
        }

    });



    final Spinner sCurrencies = (Spinner)findViewById(R.id.spCurrencies);
    ArrayAdapter<String> currencyAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item,currenciesVector);
    sCurrencies.setAdapter(currencyAdapter);

    sCurrencies.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            ItemToAdd.currency=sCurrencies.getSelectedItem().toString();
        }


        public void onNothingSelected(AdapterView<?> parentView) {
            // your code here
        }

    });


      final LinearLayout llIngredients = (LinearLayout)findViewById(R.id.layoutIngredientsList);

        final Spinner sIngredients=(Spinner)findViewById(R.id.spIngredients);
        ArrayAdapter<String> ingredientAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item,ingredientsVector);
        sIngredients.setAdapter(ingredientAdapter);

        sIngredients.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
                ingredInItem=new IngredientInItem();

                ingredToAdd.add(ingredInItem);

                TextView ingredient= new TextView(OptionAddItem.this);
                ingredient.setText(sIngredients.getSelectedItem().toString());
                llIngredients.addView(ingredient);

            }


            public void onNothingSelected(AdapterView<?> parentView) {
                // your code here
            }

        });

这里有布局

     <Spinner
         android:id="@+id/spCategories"
         android:layout_width="300dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center_vertical|center_horizontal" 
          />

    <Spinner
            android:id="@+id/spCurrencies"
            android:layout_width="300dp" 
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal" 
             />


   <Spinner
            android:id="@+id/spIngredients"
            android:layout_width="300dp" 
             android:layout_height="wrap_content"  
    android:layout_gravity="center_vertical|center_horizontal"  />

0 个答案:

没有答案