2017-03-09 48 views
-1

这里是我的代码:OnEditorActionListener与imeOptions actionNext不工作

<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; 
     } 
    });` 

不幸的是,当我按下键盘上的任何一个按钮发生。光标不会跳转到下一个字段。 我看不出有什么我失踪

回答

0

按照Doc

IME_ACTION_NEXT IME_MASK_ACTION的

位:操作键进行 “下一步” 操作, 采取用户到下一个字段将接受的文本。

所以这意味着它将专注于下一个可调焦的对象,如edittext或auto complete text view。所以如果没有其他物体可以获得焦点,它将不会移动焦点。

+0

嗨@androidnoobdev,对象是一个'TextInputLayout'就像上面的那个。所以我认为它应该能够得到关注。 – DeKekem

+0

@DeKekem然后添加此属性 - android:focusable =“true” android:focusableInTouchMode =“true”并立即检查。 – androidnoobdev

0

使用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 
    } 
}); 
+0

Hi @ rafsanahmad007。我为我的特定操作设置了处理= true,然后由该方法返回。 – DeKekem

+0

检查编辑.. @ DeKekem – rafsanahmad007