首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OnEditorActionListener与imeOptions actionNext不工作

OnEditorActionListener与imeOptions actionNext不工作
EN

Stack Overflow用户
提问于 2017-03-09 17:25:44
回答 2查看 2K关注 0票数 1

这是我的代码:

代码语言:javascript
复制
<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代码:

代码语言:javascript
复制
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按钮时,什么也不会发生。光标不会跳转到下一个字段。我看不出我错过了什么

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-03-09 17:42:07

按照医生的说法

IME_ACTION_NEXT IME_MASK_ACTION:操作键执行" next“操作,将用户带到将接受文本的下一个字段。

因此,这意味着它将专注于下一个可聚焦的对象,如编辑文本或自动完整文本视图。因此,如果没有其他对象能够获得焦点,它将不会移动焦点。

票数 0
EN

Stack Overflow用户

发布于 2017-03-09 17:31:32

使用android:inputType="text"表示TextInputEditText

尝试在您的操作中调用view.requestFocus();

代码语言:javascript
复制
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
    }
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42701743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档