Java developer.android.com上的editText.setOnEditorActionListener错误
我在上面看到了处理软键盘IME_操作的代码:Java developer.android.com上的editText.setOnEditorActionListener错误,java,android,Java,Android,我在上面看到了处理软键盘IME_操作的代码: EditText editText = (EditText) findViewById(R.id.search); editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boo
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
如果您看到,这段代码不起作用,因为mehod OnEditorActionListener用于TextView类型
那么,什么是正确的方法来处理软键盘的IME_操作呢?您需要在响应操作之前指定imeOption
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/search_hint"
android:inputType="text"
android:imeOptions="actionSend" />
您需要在响应操作之前指定imeOption
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/search_hint"
android:inputType="text"
android:imeOptions="actionSend" />
您应该将false返回到onEditorAction方法。您应该将false返回到onEditorAction方法。请改用ButterKnife
@OnEditorAction(R.id.editText)
protected boolean actionDo(int actionId){
if (actionId == EditorInfo.IME_ACTION_DONE) {
doCalculate();
return true;
}
return false;
}
它起作用了 请改用黄油刀
@OnEditorAction(R.id.editText)
protected boolean actionDo(int actionId){
if (actionId == EditorInfo.IME_ACTION_DONE) {
doCalculate();
return true;
}
return false;
}
它起作用了 是一个文本视图。这是处理ime操作的正确方法,我正在我的一个应用程序中使用它apps@Pangedittext继承textview,但不是textview@IllegalArgument好你说得对。EditText扩展了TextView。@wwwanaya在if外部尝试Log.e,看看会发生什么?还有一个Log.e在onResume中,以防万一。An是一个文本视图。这是处理ime操作的正确方法,我正在我的一个应用程序中使用它apps@Pangedittext继承textview,但不是textview@IllegalArgument好你说得对。EditText扩展了TextView。@wwwanaya在if外部尝试Log.e,看看会发生什么?还有一个Log.e在Resume上,以防万一。