title: How to create multiple onClick methods in android
body: <p>I'm trying to make an application that has multiple buttons, and when each button is pressed, it will start a new timer and display the time on the text view assigned to that button. I have successfully made one of the buttons create a working timer, however I'm having trouble making another button do the same thing for a different text view.  I do not know how to create multiple onCLick methods. </p>
  
  <p>EDIT: I'm trying to make wolvesbutton do the same thing as wratihsbutton, but have a separate timer, and display it on a different text view. </p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>import java.util.Timer;
  import java.util.TimerTask;
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.os.Handler.Callback;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
      TextView textView5, textView6, textView7;
      long starttime = 0;
      //this  posts a message to the main thread from our timertask
      //and updates the textfield
     final Handler h = new Handler(new Callback() {
  
          @Override
          public boolean handleMessage(Message msg) {
             long millis = System.currentTimeMillis() - starttime;
             int seconds = (int) (millis / 1000);
             int minutes = seconds / 60;
             seconds     = seconds % 60;
  
             textView5.setText(String.format("%d:%02d", minutes, seconds));
              return false;
  
          }
      });
     //runs without timer be reposting self
     Handler h2 = new Handler();
     Runnable run = new Runnable() {
  
          @Override
          public void run() {
             long millis = System.currentTimeMillis() - starttime;
             int seconds = (int) (millis / 1000);
             int minutes = seconds / 60;
             seconds     = seconds % 60;
  
             textView5.setText(String.format("%d:%02d", minutes, seconds));
  
             h2.postDelayed(this, 500);
  
             if(seconds &gt;= 10 || minutes &gt;= 1){
                 textView5.setText("Ready");
             }
          }
      };
  
     //tells handler to send a message
     class firstTask extends TimerTask {
  
          @Override
          public void run() {
              h.sendEmptyMessage(0);
          }
     };
  
     //tells activity to run on ui thread
     class secondTask extends TimerTask {
  
          @Override
          public void run() {
              MainActivity.this.runOnUiThread(new Runnable() {
  
                  @Override
                  public void run() {
                     long millis = System.currentTimeMillis() - starttime;
                     int seconds = (int) (millis / 1000);
                     int minutes = seconds / 60;
                     seconds     = seconds % 60;
  
                     textView6.setText(String.format("%d:%02d", minutes, seconds));
                  }
              });
          }
     };
  
     class wolvesFirstTask extends TimerTask {
  
         @Override
         public void run() {
             h.sendEmptyMessage(0);
         }
    };
  
    //tells activity to run on ui thread
    class wolvesSecondTask extends TimerTask {
  
         @Override
         public void run() {
             MainActivity.this.runOnUiThread(new Runnable() {
  
                 @Override
                 public void run() {
                    long millis = System.currentTimeMillis() - starttime;
                    int seconds = (int) (millis / 1000);
                    int minutes = seconds / 60;
                    seconds     = seconds % 60;
  
                    textView6.setText(String.format("%d:%02d", minutes, seconds));
                 }
             });
         }
    };
  
  
     Timer wraiths = new Timer();
     Timer wolves  = new Timer();
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          textView5 = (TextView)findViewById(R.id.textView5);
          textView6 = (TextView)findViewById(R.id.textView5);
  
  
          Button wraithsbutton = (Button)findViewById(R.id.wraithsb);
          Button wolvesbutton =  (Button)findViewById(R.id.wolvesb);
          wraithsbutton.setText("Start");
          wraithsbutton.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  Button wraithsbutton = (Button)v;
                  if(wraithsbutton.getText().equals("Stop")){
                      wraiths.cancel();
                      wraiths.purge();
                      h2.removeCallbacks(run);
                      wraithsbutton.setText("Start");
                  }else{
                      starttime = System.currentTimeMillis();
                      wraiths = new Timer();
                      wraiths.schedule(new firstTask(), 0,500);
                      wraiths.schedule(new secondTask(),  0,500);
                      h2.postDelayed(run, 0);
                      wraithsbutton.setText("Stop");
  
                  }
              }
  
          });
  
  
      }
  
  
  
  
  }
  </code></pre>