2015-04-23 161 views

回答

0

您可以使用下面的代碼:

editText1.addTextChangedListener(new TextWatcher() { 

     @Override 
     public void onTextChanged(CharSequence s, int start, int before, 
       int count) { 
     } 

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

     @Override 
     public void afterTextChanged(Editable s) { 
     // you can write any condition or logic here. 

     if(editText1.getText().toString.equals("1"){ 
       // You can apply your logic here 
     } 

     } 
    }); 
0
public class YourClass extends Activity { 
    private EditText yourEditText; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.main); 
     yourEditText = (EditText) findViewById(R.id.yourEditTextId); 

     yourEditText.addTextChangedListener(new TextWatcher() { 

      public void afterTextChanged(Editable s) { 
       if(yourEditText.getText().toString().equals("1")) { 
        //Rest of the code goes here 
       } 
      } 

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

      } 

      public void onTextChanged(CharSequence s, int start, int before, int count) { 

      } 
     }); 
    } 
} 
0
editText1.addTextChangedListener(new TextWatcher() { 
    @Override 
    public void onTextChanged(CharSequence s, int start, int before, int count) { 

    } 

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

    } 

    @Override 
    public void afterTextChanged(Editable s) { 
     // you can write any condition or logic here. 
     String textEntered = editText1.getText().toString(); 
     if(isNumeric(textEntered)){ 
      // You can apply your logic here 
     } 
    } 
}); 

public static boolean isNumeric(String str) { 
    return str.matches("-?\\d+(.\\d+)?"); 
} 
+0

這是不需要@ ZIEM。 – Vishal

相關問題