Set focus on spinner when selected in android

前端 未结 4 1884

I have a vertical scrolling layout with multiple EditText and Spinner controls. Problem is when i choose any spinner option after selection the screen scrolls back to the l

4条回答
  •  失恋的感觉
    2021-01-05 10:28

    Here's my solution.

    mSpinner.setFocusableInTouchMode(true);
    mSpinner.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (mSpinner.getWindowToken() != null) {
                    mSpinner.performClick();
                }
            }
        }
    });
    

提交回复
热议问题