这是我的代码:
<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;
}
});`不幸的是,当我按下键盘上的next按钮时,什么也不会发生。光标不会跳转到下一个字段。我看不出我错过了什么
发布于 2017-03-09 17:42:07
按照医生的说法
IME_ACTION_NEXT IME_MASK_ACTION:操作键执行" next“操作,将用户带到将接受文本的下一个字段。
因此,这意味着它将专注于下一个可聚焦的对象,如编辑文本或自动完整文本视图。因此,如果没有其他对象能够获得焦点,它将不会移动焦点。
发布于 2017-03-09 17:31:32
使用android:inputType="text"表示TextInputEditText
尝试在您的操作中调用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
}
});https://stackoverflow.com/questions/42701743
复制相似问题