Reputation: 209
I use searchview in my Android app and I would like to add a button that user presses to start the search. Based on what I read on the Internet, I can use setSubmitButtonEnabled
to invoke a submit button instead of putting a button in the layout file. Here's my code:
public void setSubmitButtonEnabled (boolean enabled) {
}
I put my setSubmitButtonEnabled in the menu inflater as below:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.mylist, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
setSubmitButtonEnabled(true);
return true;
}
Apparently I am not doing it right because when I launch my app, I don't see any submit button on the screen. What's missing or what's wrong in my code? Is the submit button supposed to appear on the keypad or on the screen? Thank you.
Upvotes: 1
Views: 3262
Reputation: 46
For this use
searchView=findViewById(R.id.search_box);
searchView.setSubmitButtonEnabled(true);
For submit button icon use
app:goIcon="@drawable/ic_arrow_forward_black_24dp"
For SearchView default expanded
app:iconifiedByDefault="false"
Upvotes: 0
Reputation: 93561
You need to call
searchView.setSubmitButtonEnabled(true)
Why would you create your own version with no body and expect it to do anything?
Upvotes: 8