Android authoritative Programming Guide Challenge Exercise 25 Chapter depth Optimization photogallery application

Source: Internet
Author: User

You may have noticed that when you submit a search, Recyclerview waits a few more hours to refresh the display of the search results. Take the challenge and make the search process smoother. Once the user submits the search, it hides the soft keyboard, and the Searchview view (back to the initial state of the search button is displayed). One more challenge. When the user submits the search, it initializes the Recyclerview and displays a search result loading status interface (using the status indicator). After downloading to the JSON data, delete the status indicator. In other words, once you start to download the image,

The load status should not be displayed

1. Submit search, Hide soft keyboard, searchview;

Change Searchview to a member variable, add an Inputmethodmanager object, and instantiate it in the OnCreate () method.

Private Inputmethodmanager Minputmethodmanager;     Private  = (Inputmethodmanager) getactivity (). Getsystemservice (Context.input_method_service);

Add hidden soft Keyboard in Photogalleryfragment, the method of Searchview, the code is as follows:

Private void Hintsoftinputandsearchfield () {        = getactivity (). Getcurrentfocus ();         if NULL ) {            return;        }         // Folding Soft Keyboard        Msearchview.onactionviewcollapsed ();  // the method of Searchview is closed.     }

You can then call it in the Onquerytextsubmit () method of the Searchview listener.

Msearchview.setonquerytextlistener (NewSearchview.onquerytextlistener () {@Override Public BooleanOnquerytextsubmit (String s) {//when you submit a search query. This method executes. LOG.D (TAG, "Onquerytextsubmit:" +s); Querypreferences.setstoredquery (Getactivity (), s); //stores user-submitted query information. Updateitems (); Hintsoftinputandsearchfield ();  // How to hide the keyboard mprogressdialog=Getdialog ();                Mprogressdialog.show (); return true; }            ......         });

2. Displays a search results loading status interface (using a status indicator) that is deleted when downloading to JSON data.

1. Add a progressdialog member variable.

 Public   ProgressDialog Mprogressdialog;

2. Let the dialog box appear in the Onquerytextsubmit () method of the Searchview listener. (Show when searching)

mprogressdialog=  New  ProgressDialog (getactivity ());                Mprogressdialog.setmessage ("Loading ...");                Mprogressdialog.setcancelable (true);                Mprogressdialog.show ();

3. Remove the dialog box in the OnPostExecute () method in the Fetchitemstask class (gets the data closed)

@Override         protected void OnPostExecute (list<galleryitem> items) {            = items;             if (Mitems.size () > 0) {  // If there is data then close                 Mprogressdialog.dismiss ();             }            Setupadapter ();        }

Android authoritative Programming Guide Challenge Exercise 25 Chapter depth Optimization photogallery application

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.