Today, when you're doing a search box, it's easy to do something after you've got the focus, and it's a simple way to do it, to bind Onfocuschangelistener events, implement Onfocuschange (View V, boolean hasfocus), The second parameter is to determine the focus or lose focus, so that I can achieve the desired effect, the code is as follows:
EditText Searchview = (EditText) Findviewbyid (R.id.search_text); Searchview.setonfocuschangelistener ( New Android.view.View. Onfocuschangelistener () { @Override publicvoid Onfocuschange (View V, Boolean Hasfocus) { if (hasfocus) { //// Here is the processed content When the focus is received else { // handle content when the focus is lost }} );
The text box has the following method of regain focus
Searchview.setfocusable (true); Searchview.setfocusableintouchmode (true); Searchview.requestfocus (); Searchview.clearfocus (); // loss of Focus searchview.requestfocus (); // Get Focus
EditText et = (EditText) Findviewbyid (r.id.et); Et.clearfocus (); Et.setfocusable (false);
Searchedit.setontouchlistener (NewOntouchlistener () { PublicBoolean OnTouch (View V, motioneventEvent) { //TODO auto-generated Method StubSearchedit.setfocusable (true); Searchedit.setfocusableintouchmode (true); Searchedit.requestfocus (); Intent Intent=NewIntent (Getactivity (), searchactivity.class); StartActivity (Intent); return false; } });
EditText Get Focus Listener event _edittext get and lose focus action