EditTextView监听软键盘的搜索


EditText etSearch

etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {

                    String keytag = etSearch.getText().toString().trim();

                    if (TextUtils.isEmpty(keytag)) {
                        Toast.makeText(HomeSeekShopNewActivity.this, "搜索内容不能为空", Toast.LENGTH_SHORT).show();
                        return false;
                    }

            //执行搜索的操作
                    EventBus.getDefault().post(new EventBusSeekBean(etSearch.getText().toString(),type));
                    return true;
                }
                return false;
            }
        });

你可能感兴趣的:(EditText)