I want to update an EditText when a user changes focus from the edittext to another item I want to check the contents of the edittext eg is the number larger than 10 if so change it to 10.
How should I do this.
set setOnFocusChangeListener
to your 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");
}
}
});
EditText ET =(EditText)findViewById(R.id.yourtextField);
ET.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View arg0, boolean arg1) {
String myText = ET.getText();
//Do whatever
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With