title: Select spinner without triggering listener
body: <p><strong>Long version</strong> I have two spinners on my screen and when I select the one, I do certain operations, and the other spinner should display the original selection, because of design patterns. In this situation, I let the user select the elements on a list  by year, and by state. You would agree with me that when the user choose to select by year, the spinner regarding the state should display the default selection (the one that displays all of the item) and not the last selected one.</p>
  
  <p>I am trying to do this from this morning, but when I found this solution I really though I was done.</p>
  
  <p><strong>Short version</strong> I want to setSelection(0) on the spinner which is not clicked, without triggering its listener (which by the way, will setSelection(0) on the first spinner, if triggered)</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      super.onCreateView(inflater, container, savedInstanceState);
  
      // irrelevant code...
  
      mYearSpinner.setOnItemSelectedListener(onYearSelected);
      mStateSpinner.setOnItemSelectedListener(onStateSelected);
  
      // irrelevant code...
  }
  
  private AdapterView.OnItemSelectedListener onYearSelected = new AdapterView.OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          mStateSpinner.setOnItemSelectedListener(null);
          mStateSpinner.setSelection(0);
          mStateSpinner.setOnItemSelectedListener(onStateSelected);
  
          // Do something...
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) { }
  };
  
  private AdapterView.OnItemSelectedListener onStateSelected = new AdapterView.OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          mYearSpinner.setOnItemSelectedListener(null);
          mYearSpinner.setSelection(0);
          mYearSpinner.setOnItemSelectedListener(onYearSelected);
  
          // Do something...
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) { }
  };
  </code></pre>
  
  <p>But no! The listeners will just fire, indiscriminately.</p>
  
  <p>Is there someone who knows how to handle this problem?
  Why this solution wouldn't work?</p>
  
  <hr>
  
  <p>As requested, here is the full code of my <code>onCreateView(...)</code> method</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      super.onCreateView(inflater, container, savedInstanceState);
      Log.d(TAG, "onCreateView");
  
      View view = inflater.inflate(R.layout.fragment_career, container, false);
  
      mExamListView = (ListView) view.findViewById(R.id.exam_list_view);
      mYearSpinner = (Spinner) view.findViewById(R.id.select_by_year_spinner);
      mStateSpinner = (Spinner) view.findViewById(R.id.select_by_state_spinner);
      mLoadingView = view.findViewById(R.id.fragment_career_loading_spinner);
  
      mExamListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              Exam exam = (Exam) parent.getItemAtPosition(position);
              if (exam.isBookable()) {
                  FragmentManager fm = getActivity().getSupportFragmentManager();
                  SessionsDialogFragment.newInstance(exam).show(fm, null);
              }
          }
      });
  
      // Create an ArrayAdapter using the string array and a default spinner layout
      ArrayAdapter&lt;CharSequence&gt; yearAdapter = ArrayAdapter.createFromResource(getActivity(),
              R.array.spinner_year, android.R.layout.simple_spinner_item);
  
      // Specify the layout to use when the list of choices appears
      yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      // Create an ArrayAdapter using the string array and a default spinner layout
      ArrayAdapter&lt;CharSequence&gt; stateAdapter = ArrayAdapter.createFromResource(getActivity(),
              R.array.spinner_state, android.R.layout.simple_spinner_item);
  
      // Specify the layout to use when the list of choices appears
      stateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
      mYearSpinner.setAdapter(yearAdapter);
      mStateSpinner.setAdapter(stateAdapter);
  
      mYearSpinner.setOnItemSelectedListener(onYearSelected);
      mStateSpinner.setOnItemSelectedListener(onStateSelected);
  
      return view;
  }
  </code></pre>
  
  <hr>
  
  <p>I tried implementing what --- suggested and I want to report here what happens.</p>
  
  <p>When the application starts all the two listeners are executed only once.
  Then, if I select an item on the first spinner (let's say the year spinner), the expected listener is executed only once (as it should be), and so it is, if I keep selecting items on it.
  Ultimately, if I select and item on the state spinner, the listeners are executed in this way</p>
  
  <pre><code>1. onStateListener
  2. onYearListener
  3. onStateListener
  </code></pre>