Shutdown events for Android Searchview

Source: Internet
Author: User

These days the Android Searchview is used to trigger an event when it is closed.

First looked at the next, found that there is a setoncloselistener, overjoyed, think it is it, the results point to a half-day no response, and then the morning search, summed up the following several cases:

1 inside the source, implement Setoncloselistener in the Close () method, there is an empty input box, Might conflict with Searchview's Setonquerytextlistener interface Onquerytextsubmit (String query)

2 Setoncloselistener only works at 3.2, and ICS doesn't seem to work.

And the native Seachview is (Searchview) Menuitem.getactionview ();

Then you can start from the MenuItem, see if there is any incident response, a look, of course there are

Finally looked up the information, sure enough, is as follows:

if  (currentversion >= build.version_codes. Ice_cream_sandwich)  {             Menuitem.setonactionexpandlistener (New menuitem.onactionexpandlistener ()  {                  @Override                  public boolean  Onmenuitemactionexpand (Menuitem item)  {                     return true;                 }                  @Override                  public boolean onmenuitemactioncollapsE (Menuitem item)  {                     //TODO  Add Close Event                      return true;                 }             });        } else  {            msearchview.setoncloselistener (new  searchview.oncloselistener ()  {                  @Override                  public boolean onclose ()  {                    //todo  Add Close Event                      return false;                 }             });         }


Shutdown events for Android Searchview

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.