I’m using iSpeech’s API for TTS and in their example android project, they had two buttons with two onClickListeners, one for starting the speech and one for stopping. I want to keep it to one button for more space on the android screen, so that if the speech is stopped, pressing the button would start it, and if it’s started, pressing the button would stop it.
There are quite a few questions similar to this with answers indicating that it’s better to keep it to one listener one button, but I’m not really satisfied with that since the question was on multiple listeners while mine is just two.
So do I really stick to two buttons(I hope not), or is there a way to manage this with one button?
Edit
It seems my thoughts were limited by the example that was given. One listener seems to be enough for this situation. Thank you for the answers:)
You can have one listener, and have an if-else statement with a flag to use the same button to start and stop. Something like this:
You could also use setText() to change the text on the button whenever you start and stop speaking.