如何从另一个微调器中禁用微调器?

时间:2014-05-15 05:08:03

标签: java android spinner

我有3个微调器 Spinner spinner1,spinner2,spinnerAorD;

spinner1 = (Spinner)findViewById(R.id.spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(SpeedActivity.this,
            android.R.layout.simple_spinner_item, speedcutlist);


    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner1.setAdapter(adapter);
    spinner1.setOnItemSelectedListener(this);

    spinner2 = (Spinner)findViewById(R.id.spinner2);
    ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(SpeedActivity.this,
            android.R.layout.simple_spinner_item, cctimer);


    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(adapter2);
    spinner2.setOnItemSelectedListener(this);

    spinnerAorD = (Spinner)findViewById(R.id.spinnerAorD);
    ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(SpeedActivity.this,
            android.R.layout.simple_spinner_item, AorD);


    adapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerAorD.setAdapter(adapter3);
    spinnerAorD.setOnItemSelectedListener(this);
 if(spinnerAorD.getId() == R.id.spinnerAorD)
        switch (position){

            case 0:
                AD = 0;
                break;
            case 1:
                AD = 1;
                spinner1.getSelectedView();
                spinner1.setEnabled(false);
                break;

        }

我试图在AD = 1时禁用spinner1,但是它会禁用spinnerAorD本身而不是spinner1 请求解决方案谢谢

1 个答案:

答案 0 :(得分:0)

我修好了家伙感谢有关Id更改的评论引导我回答

 if (AD == 1){
        spinner1 = (Spinner)findViewById(R.id.spinner);//this line fixed it
        spinner1.getSelectedView();
        spinner1.setEnabled(false);

    }