带有 imeOptions actionNext 的 OnEditorActionListener 不起作用
OnEditorActionListener with imeOptions actionNext not working
这是我的代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/mylayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/some_layout">
<android.support.design.widget.TextInputEditText
android:id="@+id/myid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="@string/some_hint"
android:imeOptions="actionNext"
android:inputType="time"
android:maxLength="@integer/max_input_length"
android:maxLines="1"
android:singleLine="true"
android:textSize="15sp"/>
</android.support.design.widget.TextInputLayout>
和Java代码:
myField = (TextInputEditText) findViewById(R.id.myid);
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
handled = true;
}
Log.d(TAG,"handled: "+handled);
return handled;
}
});`
不幸的是,当我按下键盘上的下一步按钮时,没有任何反应。光标不会跳到下一个字段。
我看不到我错过了什么
为您的 TextInputEditText
使用 android:inputType="text"
尝试在您的操作中调用 view.requestFocus();
。
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
Log.d(TAG,"handled: "+handled);
view.requestFocus() ; //add focus to next view object
return true; //return true
}
Log.d(TAG,"handled: "+handled);
return false; //add return
}
});
根据文档
IME_ACTION_NEXT
Bits of IME_MASK_ACTION: the action key performs a "next" operation,
taking the user to the next field that will accept text.
所以这意味着它将专注于下一个可聚焦的对象,如编辑文本或自动完成文本视图。所以如果没有其他对象可以获得焦点,它就不会移动焦点。
这是我的代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/mylayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/some_layout">
<android.support.design.widget.TextInputEditText
android:id="@+id/myid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="@string/some_hint"
android:imeOptions="actionNext"
android:inputType="time"
android:maxLength="@integer/max_input_length"
android:maxLines="1"
android:singleLine="true"
android:textSize="15sp"/>
</android.support.design.widget.TextInputLayout>
和Java代码:
myField = (TextInputEditText) findViewById(R.id.myid);
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
handled = true;
}
Log.d(TAG,"handled: "+handled);
return handled;
}
});`
不幸的是,当我按下键盘上的下一步按钮时,没有任何反应。光标不会跳到下一个字段。 我看不到我错过了什么
为您的 TextInputEditText
android:inputType="text"
尝试在您的操作中调用 view.requestFocus();
。
myField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_NEXT) {
Log.d(TAG,"next");
//Do something
Log.d(TAG,"handled: "+handled);
view.requestFocus() ; //add focus to next view object
return true; //return true
}
Log.d(TAG,"handled: "+handled);
return false; //add return
}
});
根据文档
IME_ACTION_NEXT
Bits of IME_MASK_ACTION: the action key performs a "next" operation, taking the user to the next field that will accept text.
所以这意味着它将专注于下一个可聚焦的对象,如编辑文本或自动完成文本视图。所以如果没有其他对象可以获得焦点,它就不会移动焦点。