设置imeActionLabel时,EditText输入法操作无效

NIP*_*HIN 5 android android-edittext imeoptions

我有一个带有imeoptionsas 的Edittext actiongo.当按下软键盘输入按钮时,我触发了我的事件.

mModelId.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
           // if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
            if (actionId == EditorInfo.IME_ACTION_GO) {

                id = mModelId.getText().toString();
                System.out.println("Model id in Edittext:-"+ id);
                Toast.makeText(getActivity(), "You entered "+id, Toast.LENGTH_LONG).show();
                System.out.println("Before Call Volley");
                callVolley();
                handled = true;
            }
            return handled;
        }
    });
Run Code Online (Sandbox Code Playgroud)

一切正常,但是当我添加actionlabel来输入密钥时,事件没有触发. mModelId.setImeActionLabel("Search Model", KeyEvent.KEYCODE_ENTER);.可能是什么问题?

Lok*_*esh 9

试试这个

像这样声明edittext和OnEditorActionListener()

mModelId = (EditText) findViewById(R.id.edittext_id);
mModelId.setImeActionLabel("Search Model", KeyEvent.KEYCODE_ENTER);
mModelId.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
         boolean handled = false;

         if (actionId == KeyEvent.KEYCODE_ENTER) {

              id = mModelId.getText().toString();
              Toast.makeText(getActivity(), "You entered "+id,    Toast.LENGTH_LONG).show();
              callVolley();
              handled = true;
            }
            return handled;
        }
});
Run Code Online (Sandbox Code Playgroud)

并使用imeoptions作为actionGo然后重新开始它,我认为它会覆盖ImeActionLabel 一旦尝试并回复