Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android On Focus Change

Tags:

java

android

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.

like image 629
Somk Avatar asked May 16 '12 19:05

Somk


2 Answers

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");
                }
            }
        });
like image 143
Samir Mangroliya Avatar answered Oct 27 '22 00:10

Samir Mangroliya


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

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

} 
like image 45
Raheel Avatar answered Oct 26 '22 23:10

Raheel