EditText Get Focus Listener event _edittext get and lose focus action

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.