title: Programmatically pressing a imageButton doesn't execute immediately
body: <p><code>playTune</code> is called whenever a user selects a button. The problem is the line <code>myButton.setPressed(true);</code> is only called after the tune is played. This defies logic, so I'm wondering whether Android lines up events in an queue? I would like the line <code>myButton.setPressed(true);</code> to be called as it appears in the code. i.e. before a note is played.</p>
  
  <pre><code>private void playTune() {
  
    isTunePlaying = true;
  
    //Get no of notes user selected
    String selectedValue = noteCountValues[noteCountIdx];
    Log.v(LOG_TAG, "selectedValue:"+selectedValue+" noteCountIdx:"+noteCountIdx);
    int noOfNotes;
    if ("ALL".equals(selectedValue)){
     noOfNotes = 50;
    }
    else{
     noOfNotes = Integer.parseInt(selectedValue);
    }
  
    TuneManager tuneManager = TuneManager.getInstance(this);
    Log.v(LOG_TAG, "tuneNamesIdx:"+tuneNamesIdx);   
    Tune tune = tuneManager.getTune(tuneNamesIdx+1);
  
    Log.v(LOG_TAG, " tuneTitle:"+tune.getTitle()+" tuneNoOfNotes:"+tune.getNotes().size());
  
    //Initialise expectedNotes
    expectedNotes = new StringBuffer();
  
    //Get notes and play
    List&lt;Note&gt; notes = tune.getNotes();  
    //for (Note note:tune.getNotes()){
    for (int i=1; i&lt;=notes.size() &amp;&amp; i&lt;=noOfNotes; i++){
  
     Log.v(LOG_TAG, "i:"+i+" notesSize:"+notes.size()+" noOfNotes:"+noOfNotes);   
  
     //Highlight note
     if (isHighlightNotesOn){    
      final View myButton = (ImageButton) findViewById(R.id.middle_c);    
      myButton.setPressed(true);       
     }    
  
     Note note = notes.get(i-1);
     int notePos = soundManager.getNotePosition(note);
     Log.v(LOG_TAG, "current note:"+note.getName()+" playing notePos:"+notePos+" setting duration:"+note.getDurationMS());   
     soundManager.playSound(notePos);
  
     //Add to expectedNotes
     expectedNotes.append(" "+note.getName()+",");   
  
     //Sleep for the duration
     try{
      Thread.currentThread().sleep(note.getDurationMS());//sleep for 1000 ms
     }
     catch(InterruptedException ie){
  
     }
    }
  
    isTunePlaying = false;  
  
    //Initialise actualNotesPlayed i.e. start from after the tine has finished
    actualNotesPlayed = new StringBuffer();     
  } 
  </code></pre>