2012-05-16 71 views
4

我想,當用戶改變從EditText上到我要檢查的EditText上例如內容的另一項目集中更新一個EditText大於10的號碼,如果因此它更改爲10Android的焦點更改

我該怎麼做。

+0

可能:http://stackoverflow.com/questions/4310525/android-on-edittext-changed-listener你有什麼你想要。 – icastell

回答

3
EditText ET =(EditText)findViewById(R.id.yourtextField); 
ET.setOnFocusChangeListener(new OnFocusChangeListener() { 
      public void onFocusChange(View arg0, boolean arg1) { 

String myText = ET.getText(); 
//Do whatever 

} 
5

設置setOnFocusChangeListener您的EditText ......

在這個線程
editText.setOnFocusChangeListener(new OnFocusChangeListener() { 

      @Override 
      public void onFocusChange(View v, boolean hasFocus) { 

       if(!hasFocus){ 
       //this if condition is true when edittext lost focus... 
       //check here for number is larger than 10 or not 
        editText.setText("10"); 
       } 
      } 
     }); 
+0

顯然晚會晚了,但在這裏使用setText會輸出警告「getTextBeforeCursor on inactive InputConnection」 –