Press enter to search and nothing happens


#1

When I type a search and hit enter nothing happens. Why is there no action when I press enter?

I have tried the sample code for 28 on my AVD and when I type and hi enter it searches twice.

Another weird thing is when I load up the AVD the next day, it brings back a query results from the previous search.

I get his weird error too, where the search bar disappears. I happens when I run MY code

If I close the AVD and run the sample code, it reverts back.


#2

I’m having a similar problem. Were you able to get this resolved?


#3

Since I had the same problem with search results maybe I can help.

In my case it was because I was going ahead through the chapter 28 with my version of PhotoGallery with the challenges implemented, I had a caching and a paging policy so I had to add some code in order to make the search work properly.
First of all, if you have a cache policy implemented, note that if you scroll down enough after making a search, at some point the results may start showing up (try “cats” as a query if you want :smiley: ). This because for the first views in the grid we’re loading the images already stored in cache. I fixed this problem by adding some lines in PhotoGalleryFragment.updateItems() in order to clear the cache before launching the search. In my case it was something like this:

	public void updateItems() {
		
		if (mMemoryCache != null){
			//Flushing the cache due to the needing of new elements in the same views
			mMemoryCache.evictAll();
			current_page = 1;
			fetched_page = 0;
			scroll_position = 0;
			mItems.clear();
			Log.i(TAG, "Cache Memory flushed");
		}
		new FetchItemsTask().execute(current_page);
	}

This way, every time a we’re about to search something, updateItems() is called, the cache is cleared up and the ArrayList that stores our item is emptied since we don’t need anymore the previous thumbnails.

Since I have a paging policy too, I had to set to default my paging values as well, then, for the paging policy to keep working for the search results, I had to modify some other methods inside PhotoGalleryFragment and FlickFetchr too.

Hope this was of some help for you all.


#4

I personally don’t think that deleting the cache contents is necessary
However if you want the app to work in a proper way deleting the ArrayList contents is a MUST
Because all those URL’s from the previous search will still be contained in the array and will be (unhelpfully) displayed.
unless you delete them first
but the lruCache can take care of itself and will sooon have only valid data