Android: Spinner not getting focus properly

I have the following problem: Within ScrollView , I have a TableLayout with lots of EditTexts , Spinners , RadioGroups and so on. When the action begins, the first EditText gets focus. If I scroll down to Spinner and select an item, it automatically scrolls back to the EditText in which the focus was.

I have already tried to use the following:

 ((Spinner) findViewById(R.id.attributes_status)).setFocusable(true); ((Spinner) findViewById(R.id.attributes_status)).setFocusableInTouchMode(true); 

R.id.attributes_status is a spinner. This solves the problem of automatic scrolling, but now I have to double-click the counter (1. set focus, 2. show a list of items)!

Does anyone know how to properly set focus on Spinner ? Or how to suppress the problem of automatic scrolling without changing the behavior of Spinner ?

Thanks in advance and best regards,

Sebastian

+4
source share
2 answers

I ran into the same problem. I solved this by making the spinner focused using setFocusableInTouchMode(true) , but this leads to other problems. You can see my solution for them here .

0
source

Since this solves your problem, but I have the simplest solution to this problem that solves my problem. First of all, to hide the keyboard, you can use this:

 this.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

Then use this code:

 spinner.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if(hasFocus) YourActivity.this.spinner.performClick(); } }); 
0
source

Source: https://habr.com/ru/post/1490563/


All Articles