2011-09-01 51 views
1

我的应用程序具有用于搜索的AutoCompleteTextView。当它处于焦点时,我想禁用或更改返回键的功能以进行特定的函数调用。我在布局XML以下属性添加到AutoCompleteTextViewAndroid:关闭AutoCompleteTextView时返回键的功能(或更改功能)

android:imeOptions="actionDone" 

尝试,但它的作品在我的模拟器(当你点击进入,键盘消失),但它并没有我的设备上工作(MOTO droidx运行2.3.3)。

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

回答

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

编码愉快:)

1

对我来说,它的工作原理,如果你添加关于输入型多了一个行:

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