My program should repeat a method until a button is pressed. I tried this, but is doesn't work:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tts = new TextToSpeech(this, this);
    Button button1 = (Button)findViewById(R.id.button1);
    Button button2 = (Button)findViewById(R.id.button2);
    button1.setOnClickListener(this);
    button2.setOnClickListener(this);
}
public void onClick (View v){
    switch(v.getId()) {
    case R.id.button1: 
        mainprogram();
        break;
    case R.id.button2: 
        perform = false;
        break;
    }
}
public void mainprogram(){
    while(perform == true){
        speak();
        }
    }
(Of course I programmed the "speak()" method)
Could you tell me where the problem is or if there are any methods to solve it?
 
     
     
     
     
     
    