2017-03-09 52 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