Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SearchView OnFocusChangeListener: onFocusChange is not called at all

Tags:

I have a SearchView in an Activity; when the user executes search, a Fragment containing the search results is adding to the same Activity.

Now what I want is that when the SearchView is clicked (so it gets the focus, and the user types there), the Fragment already displayed (containig the search results) should become dim/blurred.

So I tried to set an OnFocusChangedListener for the SearchView in the onActivityCreated life cycle callback method of the Fragment, but it does not seem to be called at all.

final Activity myActivity = getActivity();         Log.i(TAG, "myActivity>"+myActivity.toString());//check         SearchView mySearchView = (SearchView) myActivity.findViewById(R.id.searchActivity_searchView);         Log.i(TAG, "mySearchView>"+mySearchView.toString());//check         mySearchView.setOnFocusChangeListener(new OnFocusChangeListener() {             @SuppressLint("NewApi")             @Override             public void onFocusChange(View v, boolean hasFocus) {                 Log.i(TAG, "onFocusChange OF OnFocusChangeListener IN SearchResultsFragment CALLED.");                 if (hasFocus) {                     myActivity.getWindow().setDimAmount(1.0f);                 }             }         }); 

So am I missing something? What should I do to get the onFocusChanged called when the user clicks and thus activites the SearchView to type their Search query in it?

Note: If an entire SSCCE's code is required, please ask in comments, I'll post it.

like image 804
Solace Avatar asked Jan 14 '15 13:01

Solace


1 Answers

Sorry for late answer, but I had the same problem and found this question during search, so it might perhaps help other people.

Have you tried using mySearchView.setOnQueryTextFocusChangeListener() instead of mySearchView.setOnFocusChangeListener()?

Worked for me.

like image 160
Benjamin Scharbau Avatar answered Sep 20 '22 11:09

Benjamin Scharbau