0

I'm trying to catch when the user clicks done using soft keyboard. Following code is not working, but an almost identical code is working on another page. What is wrong with this code? Debugger shows it never calls listeners. It's not calling login function too.

I tried to add options to view file, and even custom one.

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

Update: when I move statement to another function, It works.

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

}
Mohamed
  • 1,251
  • 3
  • 15
  • 36

1 Answers1

0

Try to use this like mentioned in :

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