2017-03-01 86 views
0

我正在開發一個應用程序,我需要檢測何時將數字添加到edittext。Edittext的焦點或不是java android studio

如果有任何的EditText改變,其他的將被禁用

etdec = (EditText)findViewById(R.id.etdec); 
    etbi = (EditText)findViewById(R.id.etbi); 
    ethex = (EditText)findViewById(R.id.ethex); 
    etOctal = (EditText)findViewById(R.id.etOct); 
+0

實現addTextChangedListener – akhilesh0707

回答

0

這將是您的請求例如:

public class Main extends AppCompatActivity implements TextWatcher { 

    private EditText etdec, etbi, ethex, etOctal; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     etdec = (EditText)findViewById(R.id.etdec); 
     etbi = (EditText)findViewById(R.id.etbi); 
     ethex = (EditText)findViewById(R.id.ethex); 
     etOctal = (EditText)findViewById(R.id.etOct); 
     if(etdec) etdec.addTextChangedListener(new TextWatcher(){ 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
       etbi.setEnabled(false); 
       ethex.setEnabled(false); 
       etOctal.setEnabled(false); 
      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       kaufort_feld.setEnabled(false); 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }); 
     if(etbi) etbi.addTextChangedListener(new TextWatcher(){ 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       etdec.setEnabled(false); 
       ethex.setEnabled(false); 
       etOctal.setEnabled(false); 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }); 
     if(ethex) ethex.addTextChangedListener(new TextWatcher(){ 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       etdec.setEnabled(false); 
       etbi.setEnabled(false); 
       etOctal.setEnabled(false); 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }); 
     if(etOctal) etOctal.addTextChangedListener(new TextWatcher(){ 

      @Override 
      public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
      } 

      @Override 
      public void onTextChanged(CharSequence s, int start, int before, int count) { 
       etdec.setEnabled(false); 
       etbi.setEnabled(false); 
       ethex.setEnabled(false); 
      } 

      @Override 
      public void afterTextChanged(Editable s) { 

      } 
     }); 
    } 
}