SearchView imeOptions and onQueryTextSubmit support

前端 未结 2 1472
醉酒成梦
醉酒成梦 2021-01-21 08:54

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

2条回答
  •  长情又很酷
    2021-01-21 09:26

    I had the same problem, the problem lies onSubmitQuery() in SearchView.java

    private void onSubmitQuery() {
        CharSequence query = mQueryTextView.getText();
        if (query != null && TextUtils.getTrimmedLength(query) > 0) {
    

    Empty query's are not supported so I had to download and use ActionBarSherlock and then modify this method.

    This is how my onSubmitQuery() looks like now

    private void onSubmitQuery() {
         CharSequence query = mQueryTextView.getText();
         if (query == null) {query = "";}
         if (mOnQueryChangeListener == null
                 || !mOnQueryChangeListener.onQueryTextSubmit(query.toString())) {
             if (mSearchable != null) {
                 launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, query.toString());
                 setImeVisibility(false);
             }
             dismissSuggestions();
         }
     }
    

    Hope this helps.

提交回复
热议问题