Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我能';t在actionbar上的搜索字段中检测文本更改_Android - Fatal编程技术网

Android 我能';t在actionbar上的搜索字段中检测文本更改

Android 我能';t在actionbar上的搜索字段中检测文本更改,android,Android,我有以下代码,onOptionItemSelected()永远不会运行。它永远不会到达Log.i(“,”开关”)

我有以下代码,onOptionItemSelected()永远不会运行。它永远不会到达
Log.i(“,”开关”)
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getSupportMenuInflater().inflate(R.menu.category_menu, menu);
        Log.i("", "created menu");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.i("", "switch");
        switch (item.getItemId()) {
        case 0:
            Log.i("", "case 0");
            search = (EditText) item.getActionView();
            search.addTextChangedListener(filterTextWatcher);
            search.requestFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        }
        return true;
    }

    private TextWatcher filterTextWatcher = new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            Log.d("", "my search logic");
        }

    };

类别菜单中是否有菜单项
OnOptions ItemSelected
在触摸菜单项时调用,而不仅仅是在菜单本身打开时调用。如果您确实有菜单项,请触摸其中一项,然后在LogCat中,您应该会看到您的“切换”日志语句。

也许您更想要这样的内容。SearchView已经有一个侦听器来处理查询

在OnCreateOptions菜单(菜单菜单)中:


没有必要骂人,用它来代表“多么可怕的失败”。。。
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            Log.w("SEARCH","Search: "+s);
            startSearch(s,true,null,true);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            Log.w("SEARCH","Typing: "+s);
            return false;
        }
    });