0

如何在单个布局中使用多个微调器,即在创建时设置设置 On Item Selected Listener

4

1 回答 1

0

欢迎来到 SO。您绝对应该阅读常见问题解答以了解要问什么样的问题以及如何问。如果您想要好的答案并且不希望您的权限被撤销,您需要更具体地说明您的问题并添加相关代码和错误消息以表明您已经尝试过。但既然你是新来的,我就给你这个。最简单的方法是在通过 xmlonCreate()获得对每个的引用后将侦听器附加到每个spinner

spinner1.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this;

然后把方法放在外面onCreate()

@Override
public void onItemSelected(AdapterView<?> parent, View view, int arg2,
        long arg3) 
{
    // do whatever you need here depending on what is selected
    // you can use a case statement and switch on the id to get the spinner (parent) or view

}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

并添加Implements OnItemSelectedListener您的Activity签名。祝你好运,请在以后提出更具体的问题,并添加代码表明你已经尝试过了。

于 2013-04-05T22:36:02.623 回答