Android. onEditorAction never called

大憨熊 提交于 2020-01-03 09:20:06

问题


I'm trying to catch the event of removing keyboard from the screen and i'm using OnEditorActionListener class. However, its onEditorAction method never gets called.

This is my EditText in XML:

<EditText
    android:id="@+id/editTextSearch"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="20dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="50dp"
    android:layout_weight="0.05"
    android:background="@color/white"
    android:ems="10">
</EditText>

This is how i work with it in java file:

private void createTextEdit()
{
    EditText searchTextField = (EditText)findViewById(R.id.editTextSearch);
    searchTextField.addTextChangedListener(new TextWatcher()
    {
        public void afterTextChanged(Editable s)
        {
           System.out.println("AFTER TEXT CHANGED");                                                             
        }
        public void beforeTextChanged(CharSequence s,
        int start, int count, int after)
        {
             System.out.println("BEFORE TEXT CHANGED " + s);
        }

        public void onTextChanged(CharSequence s,
                int start, int before, int count)
        {
            System.out.println(s);
        }
    });

    searchTextField.setOnEditorActionListener(new OnEditorActionListener()
    {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
        {

            System.out.println("ACTION ID " + actionId);//NEVER CALLED

            if(actionId == EditorInfo.IME_ACTION_DONE)
            {
                System.out.println("ACTION DONE!!!!!!!!!!");
                return true;
            }

            return false;
        }
    });

    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(searchTextField, InputMethodManager.SHOW_IMPLICIT);
}

No matter what i do with searchTextField whether i start editing or finish it, the needed method is never fired. What am i doing wrong?


回答1:


Same problem here on a Nexus 7.

I thought it was the imeOptions, but no.

It works in my tablet if i set android:inputType="text".

I assume that it works with other inputType.

I think it's a bug on Nexus.



来源:https://stackoverflow.com/questions/15202771/android-oneditoraction-never-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!