code: 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!");
        }
      }
    }
docs: Set the default spinner item using its index
  
  @param position the item's position