title: Set Selected Items Without Triggering OnItemSelectedListener
body: <p>I have been struggling with this for days now, I have a list of items I am loading from my server.  When the items are loaded I display the list and I set the selected item for each spinner.  Now these are my problems.</p>
  
  <p>Case 1:
  The onItemSelectedListener for each item in my adapter gets triggered on page load.</p>
  
  <p>So I did some research online and decided to use a variable to check the state.  When the view is created I set firstTime to true in the on click listener like this:</p>
  
  <pre><code>viewHolder.spStatus.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
      @Override
      public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
          if (!firstTime) {
              AlertDialog.Builder builder = new AlertDialog.Builder(context);
  
              builder.setTitle("Confirm");
              builder.setMessage("Are you sure you want to change this?");
  
              builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
  
                  public void onClick(DialogInterface dialog, int which) {
                      int selectedPosition = Integer.parseInt(viewHolder.id.getTag().toString());
                      String selectedId = viewHolder.id.getText().toString();
                      updateStatus(selectedPosition, selectedId,
                              ((ArrayAdapter&lt;String&gt;) viewHolder.spStatus.getAdapter())
                                      .getItem(selectedPosition));
                  }
  
              });
  
              builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
  
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      // Do nothing
                      dialog.dismiss();
                  }
              });
  
              AlertDialog alert = builder.create();
              alert.show();
          }
  
          firstTime = false;
      }
  
      @Override
      public void onNothingSelected(AdapterView&lt;?&gt; parent) {
          // Do Nothing
      }
  });
  </code></pre>
  
  <p>Now this is what happens when I do this it's either when I scroll the onItemSelected change listener fires depending on where I put <code>firstTime=false</code> or when I filter the list I have to tap twice before the event is triggered.</p>