title: Swapping between Listeners in Android
body: <p>I'm having problems dealing with <strong>a button</strong> and its <strong>two listeners</strong>. 
  My objective is swapping two listeners of a button using it.
  It's not the behaviour I need. I need to release the button, and then click it again in a different way (with a different listener).
  So..  I "onTouch" this button, and when I release my finger, I need to swap its "onTouch" listener to an "onClick()" one.</p>
  
  <p>Now, I tried to accomplish my goal doing the following:</p>
  
  <pre><code> final View.OnClickListener play_listener = new View.OnClickListener() {
          @Override
          public void onClick(View v) { Utility.playRecording(mediaPlayer); } };
  
   final View.OnTouchListener rec_listener = new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent event) {
              if (Utility.checkPermission(view.getContext())) {
                  switch (event.getAction()) {
                      case MotionEvent.ACTION_DOWN:
                          Utility.startRecording(recorder, output_formats, currentFormat, file_exts, timer);
                          break;
  
                      case MotionEvent.ACTION_UP:
                          Utility.stopRecording(recorder, timer);
                      //disabling my onTouch Listener
                          recplay_button.setOnTouchListener(null);
                      //Setting a new listener for the same button
                          recplay_button.setOnClickListener(play_listener);
                      //Changing its color.
                          recplay_button.setBackground(getDrawable(R.drawable.coloranimreverse));
                          break;
                  }
              } else {
                  Utility.requestPermission(view.getContext());
              } return false; }};
  </code></pre>
  
  <p>So, the swapping works but I can't get the reason why after setting the onClickListener it also execute it, playing the sound I set in the other listener. Does the MotionEvent.ACTION_UP counts as a click? </p>
  
  <p>Do you know how can I get through this? What I need is just not execute the onClick() listener in the same moment that I set it in the OnTouch() listener.</p>
  
  <p>Thank you all.</p>