我怎么知道用户何时点击了搜索键?

How do i know when the user tapped the search key?

我在我的应用程序中实现了关键字搜索,但是当我点击软键盘上的搜索(即问号)键时,我没有收到任何回调。我已经在我的 EditText 中添加了一个 TextWatcher,但是当我点击搜索时它没有被调用。 Activity.onKeyUp() 也没有被调用。

有什么方法可以知道用户何时点击了软键盘上的搜索键?

提前致谢...

像这样使用 searchView

 SearchView sv=(SearchView)findViewByid(R.id.sv);
      sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    return false;
                     //here is when clicking the search button in keyboard
                }

                @Override
                public boolean onQueryTextChange(String s) {
                   //here is when the text change
                    return false;
                }
            });

编辑 我已经找到办法了:

在xml

  <EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editText"  
    android:imeOptions="actionSearch"
    android:inputType="text"/>

在 onCreate 方法中

 ((EditText)findViewById(R.id.editText)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                Toast.makeText(MainActivity.this,"searching",Toast.LENGTH_LONG).show();
                return true;
            }
            return false;
        }
    });

就这些了