我正在尝试捕捉从屏幕上移除键盘的事件,并且我正在使用 OnEditorActionListener
类。但是,它的 onEditorAction
方法永远不会被调用。
这是我的 XML EditText:
<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 文件中使用它的方式:
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
做什么,无论我是开始编辑还是完成它,都不会触发所需的方法。我做错了什么?
最佳答案
在 Nexus 7 上也有同样的问题。
我以为是 imeOptions,但不是。
如果我设置 android:inputType="text"
,它可以在我的平板电脑上使用。
我假设它适用于其他输入类型。
我认为这是 Nexus 上的错误。
关于java - 安卓。 onEditorAction 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15202771/