2017-09-16 18 views
0

EditTextを実行中に無効にすると、onCreate()に実行されます。しかし、CheckBoxをクリックすると、このメソッドは一度実行され、再度実行を停止します。CheckBOxが有効でない状態でEditTExtを有効または無効にする

誰もがあなたがcheckBoxsetOnCheckedChangeListener内部にEditTextを初期化している回答

public void EXtraWorkCalc(){ 
    extraworkCheck = (CheckBox)findViewById(R.id.workCheck); 
    extraworkCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
     @Override 
     public void onCheckedChanged(CompoundButton compoundButton, boolean b) { 
      if (!compoundButton.isChecked()) { 
       extraSpace = (EditText) findViewById(R.id.extraWidthEtxt); 
       extraSpace.setEnabled(false); 
       extraSpace.setBackgroundColor(Color.LTGRAY); 
      } else 
       extraSpace.setEnabled(true); 
       extraSpace.setBackgroundColor(Color.WHITE); 
     } 
    }); 
} 

答えて

1

を見つけるのを助けます。そういうわけではないのです。

EditText(extraSpace)をoncreate()に初期化するか、EXtraWorkCalc()メソッドを呼び出す前に初期化してください。

移動onCreate()この行:。

extraSpace = (EditText) findViewById(R.id.extraWidthEtxt); 
+0

ヨールは右卿ですが、私のような検証、その後のonCreateでそれを初期化()としていたときにあれば(TextUtils.isEmpty(extraSpace.getText()のtoString()) ){ extraSpace.setError( "余分な仕事を入力してください"); } CheckBox ListnerのIf()ステートメントが動作していないため、数値書式例外のエラーが表示される –

関連する問題