[Solved] two buttons with onClick in same place


Try with something like this:

public class MyActivity extends Activity {
     Button buttonStart;
     Button buttonStop;

     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         buttonStart = (Button) findViewById(R.id.buttonStart);
         buttonStop = (Button) findViewById(R.id.buttonStop);
         buttonStart.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
                 //for example mediaPlayer.start(); if you have a media player
             }
         });
         buttonStop.setOnClickListener(new View.OnClickListener(){
             public void onClick(View v){
                 //do what you want - for example mediaPlayer.stop();
             }
         });
    }
}

After your comment: then use a single button and check if it is recording for example:

public class MyActivity extends Activity {
     Button button;
     boolean isRecording = false;

     protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);

         setContentView(R.layout.content_layout_id);

         button = (Button) findViewById(R.id.myButton);
         button.setText("Start");
         button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Perform action on click
                 if(isRecording == fasle){
                     //start recording
                     isRecording = true; //set the variable to know that it is recording
                     button.setText("Stop");
                 } else {
                     //stop recording
                     isRecording = false; //set the variable to know that it is not recording
                     button.setText("Start");
                 }
             }
         });
    }
}

2

solved two buttons with onClick in same place