Android studio有两个spinner组件进行监听的代码
时间: 2024-05-28 19:09:58 浏览: 171
可以参考以下代码:
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// 处理 spinner1 选中项的逻辑
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// 处理 spinner2 选中项的逻辑
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
阅读全文