所以我在屏幕上有按钮(不是软键盘),但我想要一些禁用(无法点击)当你选择某个< strong>微调器选项。就像我有按钮0-9(用于数字输入),如果选择“Base 2”(微调器选择0),我希望禁用除0和1之外的所有按钮。
答案 0 :(得分:1)
您可以添加一个OnItemClickListener并对给出的选项作出反应,例如这样
spinner.setOnItemClickListener(new AdapterView.OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if(position == 1)
button.setClickable(false);
}
});
答案 1 :(得分:1)
Spinner
不支持setOnItemClickListener
。如果您尝试使用它,您将获得例外:
java.lang.RuntimeException: setOnItemClickListener cannot be used with a spinner
因此,您应该使用setOnItemSelectedListener
:
spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int position, long id) {
Toast.makeText(MyActivity.this, "position= "+position+" / id= "+id, Toast.LENGTH_LONG).show();
switch(position) {
case 0:
button0.setClickable(true);
button1.setClickable(false);
break;
case 1:
button0.setClickable(false);
button1.setClickable(true);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}});