android - Applying OnFocusChangeListener and OnItemSelectedListener to Spinner -


i have spinner works fine standard onitemselectedlistener present set of options:

s.setadapter(adapter); s.setonitemselectedlistener(new onitemselectedlistener() {     public void onitemselected(adapterview<?> arg0, view arg1,             int selectedposition, long arg3) {          if (selectedposition == 0) {             // stuff         } else {             // other stuff         }     }      public void onnothingselected(adapterview<?> arg0) {     } }); 

however, have new requirement when user clicks on spinner use it, corresponding button disabled. have added following onfocuschangelistener spinner:

s.setfocusable(true); s.setfocusableintouchmode(true); s.setonfocuschangelistener(new onfocuschangelistener() {      @override     public void onfocuschange(view v, boolean hasfocus) {         if (hasfocus) {             distancebutton.setenabled(false);         } else {             distancebutton.setenabled(true);         }     }  }); 

this works, , disables button. however, spinner need 2 clicks bring options, when without onfocuschangelistener needed 1 click. there way combine both operations 1 listener?

thanks...

try call super.onfocuschange(v, hasfocus) after if-clause.

 public void onfocuschange(view v, boolean hasfocus) {         if (hasfocus) {             distancebutton.setenabled(false);         } else {             distancebutton.setenabled(true);         }         super.onfocuschange(v, hasfocus);     } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -