GetSelectedItemPosition spinner gives incorrect result

When I try to get the selected position of the selected item using getSelectedItemPosition, I always get 0 as the result. I created a test using ItemSelectedListener, but it gives strange results.
Here is my code:

this.chooseSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) { Log.d("TEST", "val1: " + arg2 + " val2:" + arg3); Log.d("TEST", "pos: " + ItemOption.this.chooseSpinner.getSelectedItemPosition()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); 

And the logs give this result:

 08-08 20:44:58.017: D/TEST(15078): val1: 0 val2:0 08-08 20:44:58.017: D/TEST(15078): pos: 0 08-08 20:45:00.142: D/TEST(15078): val1: 2 val2:2 08-08 20:45:00.142: D/TEST(15078): pos: 0 

What could be causing this problem? Thanks in advance for any help.

+4
source share

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


All Articles