I found a very ugly solution to this (the "action" takes place in the onConfigurationChanged method):
Before calling setContentView , check if the drop-down list (*) is displayed, and if so, save the position that is currently selected in the counter ( int pos = spinner.getSelectedItemPosition() ).
After calling setContentView and installing the spinner adapter, if the drop-down list was shown in step 1, force the drop-down list to be displayed by calling Click on the spinner:
spinner.setSelection(pos);
(*) Checking the display of the drop-down list is the more difficult part. I have not yet found a method that allows me to find out if a drop-down list is displayed, so I had to do the following:
Hold down the spinner button in a boolean variable (named, for example, isClicked ).
Set onTouchListener for the counter and in the onTouch method set isClicked to true (when clicking on the spinner, dropdwon opens, so isClicked == true means that a drop-down list is displayed).
Override onKeyDown or onKeyUp , and when you click the Back button, if isClicked is true, set it to false (I assumed that pressing isClicked == true means closing the drop-down list).
Use the isClicked value in onConfigurationChanged to check if a drop-down is displayed.
As I said, this is an ugly fix, but this is the only thing I could come up with so far. If anyone has any other ideas, send them to us.
source share