安卓.从不调用onEditorAction [英] Android. onEditorAction never called
问题描述
我正在尝试捕获从屏幕上删除键盘的事件,并且我正在使用OnEditorActionListener
类.但是,它的onEditorAction
方法永远不会被调用.
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.
这是我的XML的EditText:
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>
这就是我在Java文件中使用它的方式:
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);
}
无论我是开始编辑还是完成searchTextField
的工作,都永远不会触发所需的方法.我在做什么错了?
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?
推荐答案
在Nexus 7上存在相同的问题.
Same problem here on a Nexus 7.
我以为是imeOptions,但没有.
I thought it was the imeOptions, but no.
如果我设置了android:inputType="text"
,它将在我的平板电脑上正常工作.
It works in my tablet if i set android:inputType="text"
.
我认为它可以与其他inputType一起使用.
I assume that it works with other inputType.
我认为这是Nexus上的错误.
I think it's a bug on Nexus.
这篇关于安卓.从不调用onEditorAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!