2017-08-02 62 views
0

ソフトキーボードを使用してユーザーが完了をクリックしたときにキャッチしようとしています。次のコードは動作しませんが、ほぼ同じコードが別のページで動作しています。このコードで何が問題になっていますか?デバッガは、リスナーを呼び出さないことを示しています。それはlogin関数を呼び出すのでもありません。IMEアクションをキャッチ

私はビューファイルにカスタムオプションを追加することを試みました。

//view 
<EditText 
    android:id="@+id/password" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="@string/prompt_password" 
    android:inputType="textPassword" 
    android:maxLines="1"/> 

//java, onCreateView (b is data binding) 
b.password.setImeOptions(EditorInfo.IME_ACTION_DONE); 
RxTextView.editorActionEvents(b.password) 
    .subscribe(a -> { 
     login(); 
    }); 

//or old way is not working too 
b.password.setOnEditorActionListener((v, actionId, event) -> { 
     login(); 
     return false; 
    }); 

更新: 別の機能に文を移動すると動作します。

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 
    RxTextView.editorActionEvents(b.password) 
      .subscribe(a->{ 
       login(); 
      }); 

} 

答えて

0

に言及した。このようなを使用してみてください:

Android Use Done button on Keyboard to click button

b.password.setOnEditorActionListener(new OnEditorActionListener() { 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
      if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { 
       Log.i(TAG,"Enter pressed"); 
      }  
      return false; 
     } 
    }); 
+0

答えてくれてありがとう、しかし、動作しませんでした。 – MmtBkn

関連する問題