Android:当AutoCompleteTextView被聚焦时,禁用(或更改功能)返回键

adj*_*fac 1 android return

我的应用程序有一个用于搜索的AutoCompleteTextView.当它处于焦点时,我想禁用或更改返回键的功能到特定的函数调用.我尝试在我的布局xml中将以下属性添加到AutoCompleteTextView

    android:imeOptions="actionDone"
Run Code Online (Sandbox Code Playgroud)

但是它可以在我的模拟器上工作(当你点击输入时,键盘消失了)但它在我的设备上不起作用(运行2.3.3的moto droidx).

有人可以告诉我如何将返回键链接到特定功能(在我的情况下,搜索功能)与android:imeOptions ="actionGo"?

Pan*_*mar 8

在家庭setOnEditorActionListener活动中编写代码EditText.喜欢

autoEditText.setOnEditorActionListener(new OnEditorActionListener() {

            public boolean onEditorAction(TextView v, int actionId,
                    KeyEvent event) {
                if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                    InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                   // in.hideSoftInputFromWindow(autoEditText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                   //Commented line is for hide keyboard. Just make above code as comment and test your requirement
                   //It will work for your need. I just putted that line for your understanding only
                   //You can use own requirement here also.
                }
                return false;
            }
        });
Run Code Online (Sandbox Code Playgroud)

快乐编码:)