当我点击并打开“Spinner对话框下拉列表”时,
我想在相同的布局中点击并立即触发另一个微调器下拉列表。
例:
1.“spinner1”和“spinner2”在相同的布局中
2.当我点击“spinner1”并打开其下拉列表时,
3.然后我想点击“spinner2”并立即打开它的下拉列表
4.无需等待“spinner1”关闭其菜单点击“spinner2”
5.(以及“spinner1”应关闭其菜单)
当我打开任何下拉列表后点击时,屏幕上的任何位置都会被阻止以关闭打开的下拉列表,在下拉列表关闭之前无法点击任何视图?
在Android中打开下拉列表时是否可以点击任何其他视图?
答案 0 :(得分:0)
试试这段代码:
Spinner sp1 = (Spinner) findViewById(R.id.sp_category);
final Spinner sp2 = (Spinner) findViewById(R.id.sp_category2);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
sp1.setAdapter(adapter);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
R.array.values, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
sp2.setAdapter(adapter2);
sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
sp2.performClick();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}