Set focus on spinner when selected in android

前端 未结 4 1896

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:42

    Use this to avoid EditText Focus :

    scrollView = (ScrollView) findViewById(R.id.scrollView_id);
            scrollView.setOnTouchListener(new OnTouchListener() {
                // to solve foocus problem on scrolling
                public boolean onTouch(View v, MotionEvent event) {
                    if (myEditText.hasFocus()) {
                        myEditText.clearFocus();
                    }
                    if (myEditText1.hasFocus()) {
                        myEditText1.clearFocus();
                    }
    
                    return false;
                }
            });
    

提交回复
热议问题