Search code examples
android-fragmentsandroid-edittextandroid-spinnerandroid-radiogroup

How to set focus on spinner from edit text soft keyboard next button click?


Example: I've registration form fields like:

  1. Enter Name -> Edit text (default set focus)
  2. Gender -> radio button list (a.male and b.female)
  3. City list-> Spinner

I want to make like these:

  1. Fragment is load and focus on edit text filed and open a soft keyboard.
  2. When I pressed the soft keyboard next key set focus on gender to select male or female.
  3. Then pressed again soft keyboard next key set focus on city list(spinner) to select city.

It is possible to make such functionality?


Solution

  • editTextBefore.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_NEXT) {
            hideKeyboard();
            textView.clearFocus();
            spinner.requestFocus();
            spinner.performClick();
        }
        return true;
    }
    });
    

    This answer copy from LINK