在选择微调器中的特定项时启用edittext

时间:2015-01-27 07:53:06

标签: android

我尝试使用以下代码在从Spinner中选择“其他”时启用EditText,并在选择其他项时禁用EditText,但没有任何反应:

   spin.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
        {
            final String SelectedLeave = spin.getSelectedItem().toString();
            Toast msg2 = Toast.makeText(getApplicationContext(),SelectedLeave,Toast.LENGTH_SHORT);
            msg2.show();
            if(SelectedLeave == "Others"){
                txt1.setEnabled(true);
                txt1.setInputType(InputType.TYPE_CLASS_TEXT);
                txt1.setFocusableInTouchMode(true);
                txt1.setFocusable(true);
            }else{
                txt1.setEnabled(false);
                txt1.setInputType(InputType.TYPE_NULL);
                txt1.setFocusableInTouchMode(false);
                txt1.setFocusable(false);
            };
        }
        public void onNothingSelected(AdapterView<?> arg0)
         {
                  // TODO Auto-generated method stub                  
         }

});

由于

0 个答案:

没有答案