I'm currently using ActionBarSherlock 4.2 and it's SearchView widget in my app.
I wanted to make it submit query even though it's empty. I tried to set imeOptions and OnKeyListener but both were ignored without a reason.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Log.d(TAG, "onCreateOptionsMenu");
inflater.inflate(R.menu.interactive_map, menu);
mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
mSearchView.setImeOptions(EditorInfo.IME_ACTION_GO);
mSearchView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
Log.d(TAG, "keyCode: " + keyCode);
Log.d(TAG, "Action: " + event.getAction());
if(keyCode == EditorInfo.IME_ACTION_SEARCH){
onQueryTextSubmit(""+mSearchView.getQuery());
}
return false;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
onKey's never get triggered as both Logcat entries never appear in Logcat window. Not sure if this being inside SherlockFragment is the problem.
Nothing special's done to the menu item as well.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_search"
android:title="@string/app_name"
android:icon="@android:drawable/ic_menu_search"
android:showAsAction="always"
android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
</menu>
Is there a way to get around this? Or is there simpler way to enable submitting when query is empty? It doesn't seems to support any configuration in the source code though.