【问题标题】:Android: disable (or change of the function of ) the return key when AutoCompleteTextView is focusedAndroid:当 AutoCompleteTextView 获得焦点时禁用(或更改功能)返回键
【发布时间】:2011-11-08 03:08:57
【问题描述】:

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

    android:imeOptions="actionDone"

但它适用于我的模拟器(当您单击 Enter 时,键盘消失)但它不适用于我的设备(运行 2.3.3 的 moto droidx)。

谁能告诉我如何使用 android:imeOptions="actionGo" 将返回键链接到特定函数(在我的例子中是搜索函数)?

【问题讨论】:

    标签: android return


    【解决方案1】:

    在EditText 家族的setOnEditorActionListener 事件中编写您的代码。喜欢

    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;
                }
            });
    

    编码愉快:)

    【讨论】:

      【解决方案2】:

      对我来说,如果您再添加一行关于输入类型的内容,它会起作用:

      android:inputType="text"
      android:imeOptions="actionDone"
      

      【讨论】:

        猜你喜欢
        • 2022-10-24
        • 2012-09-22
        • 1970-01-01
        • 1970-01-01
        • 2013-12-13
        • 1970-01-01
        • 2012-09-18
        • 2018-03-19
        • 2016-05-20
        相关资源
        最近更新 更多