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