I have a searchView which looks like this:
private void setupSearchView() {
mSearchView = (SearchView) getActivity().findViewById(
R.id.search_view_neue);
setSearchViewBackground();
mSearchView.setOnClickListener(this);
mSearchView.setOnQueryTextListener(this);
}
public boolean onQueryTextSubmit(String query) {
searchcounter = searchcounter + 1;
setSearchViewBackground();
ArrayList<WissensdokumenteRecord> documents = settingListContent(new ArrayList<WissensdokumenteRecord>());
setListAdapter(new NeueWissensdokumentItemAdapter(
inflater.getContext(), R.layout.row_example, documents));
InputMethodManager im = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(getActivity().getCurrentFocus()
.getWindowToken(), 0);
return false;
}
<SearchView
android:id="@+id/search_view_neue"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="@drawable/border_searchview"
android:maxWidth="540dp"
android:queryHint="Neue Dokumente suchen" >
</SearchView>
So, the behaviour of the search view is, that the keyboard opens by clicking the search button. Now I can search for something. Is it possible to do a search by clicking anywhere in the searchview? Does anyone has an example for me?
android.widget.SearchView. A widget that provides a user interface for the user to enter a search query and submit a request to a search provider. Shows a list of query suggestions or results, if available, and allows the user to pick a suggestion or result to launch into.
To get text of SearchView , use searchView. getQuery() .
I managed to do this in the following way:
Setup the search view on click listener
mSearchView.setOnClickListener(this);
Catch the onClick event:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.searchView:
mSearchView.onActionViewExpanded();
break;
}
}
In this way the keyboard and search are activated if you click antwhere on the search bar.
This will do exactly what you're trying to achieve.
setIconified(false)
will keep the cross icon at this end of the SearchView so that the user can still cancel the same way as if the magnifying glass was clicked.
searchView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setIconified(false);
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With