Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I tell when text is being typed into my Android SearchView on the ActionBar
    primarykey
    data
    text
    <p>I want to disable certain features of my app while the user is entering text for a search. The xml for the relevant item in my ActionBar is</p> <pre><code>&lt;item android:id="@+id/actionbar_search" android:orderInCategory="1" android:showAsAction="always|withText|collapseActionView" android:actionViewClass="android.widget.SearchView" android:icon="@drawable/earth_2508858_search_en" android:inputType="textPostalAddress" /&gt; </code></pre> <p>and in the corresponding code that I have at present to cater for the search is</p> <pre><code>@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.action_menu, menu); MenuItem DestinationTxt = menu.findItem(R.id.actionbar_search); final SearchView mySearchView = (SearchView)DestinationTxt.getActionView(); mySearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { //Hide the Keyboard imm.hideSoftInputFromWindow(mySearchView.getWindowToken(), 0); // CODE TO DO THE SEARCH return true; } }); } </code></pre> <p>I've browsed the methods on SearchView, but I didn't see anything that would tell me whether it's active or not. I'm also worried about putting in a boolean state variable to indicate when the text is being typed into the SearchView, in case some behaviour that I haven't catered for occurs (e.g. back button pressed, activity gets suspended), and somehow the state variable gets stale so that the disabled features stay disabled. So I'm looking for a robust way of doing this, all help appreciated :-).</p> <p><b>Update</b>. An answer below suggests using the interface <code>OnFocusChangeListener</code> which is implemented by the mySearchView object, and/or the mySearchView.isFocussed() method. Both sounded promising, however I've now tested and neither seem to work. Perhaps their failure has got something to do with the fact that this SearchView is in the ActionBar? In any case, I'm still after a robust solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload