如何使一个微调填充另一个微调? [英] How to make a spinner populate another spinner?

查看:188
本文介绍了如何使一个微调填充另一个微调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您会如何做一个微调填充基于第一纱厂选择另一个微调?

How would you go about making a spinner populate another spinner based on the first spinners selection?

因此​​,例如:

Spinner1项目是素食或荤食。

Spinner1 items are vegetarian or meat eater.

  <string-array name="spinnerarray_veg_meat">
    <item >Vegetarian</item>
    <item >Meat eater</item> 
   </string-array> 

然后

Spinner2将需要显示无论是素食名称或根据spinner1的选择荤食的人。

Spinner2 would then need to display either vegetarian meal names or meat eater ones depending on spinner1's selection.

推荐答案

要做到这一点,你必须设置一个 OnItemSelectedListener 你的第一个微调来填充第二个微调编程。

To do this you'll have to set a OnItemSelectedListener on your first Spinner to populate the second Spinner programmatically.

spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {

              if(position == 0) {
                   // Populate the Spinner2 with different values
              } else {
                   // Populate the Spinner2 with different values
              }

        }
        public void onNothingSelected(AdapterView<?> parent) {
            return;

        }
    });

这篇关于如何使一个微调填充另一个微调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆