public void setSelectedIndex ( int position ) { if ( adapter != null ) { if ( position >= 0 && position <= adapter . getCount ( ) ) { adapter . notifyItemSelected ( position ) ; selectedIndex = position ; setText ( adapter . get ( position ) . toString ( ) ) ; } else { throw new IllegalArgumentException ( "Position must be lower than adapter count!" ) ; } } }
Set the default spinner item using its index